Javascript-форум (https://javascript.ru/forum/)
-   Библиотеки/Тулкиты/Фреймворки (https://javascript.ru/forum/library-toolkit-framework/)
-   -   Почему не удаляется объект в массиве Phaser? (https://javascript.ru/forum/library-toolkit-framework/78870-pochemu-ne-udalyaetsya-obekt-v-massive-phaser.html)

Katy93 15.11.2019 18:01

Почему не удаляется объект в массиве Phaser?
 
При щелчке на спрайте должно происходить удаление, однако ничего не происходит. При каждом щелчке в консоле выводит ошибку:
game.js:26 Uncaught TypeError: myGroup.clear is not a function
Как сделать так, чтобы спрайт-картинка удалялась?
Пример взят с оф. сайта, только слегка изменён.
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });

function preload() {

    game.load.image('mushroom', 'images/mushroom2.png');

}

function create() {
    
    myGroup = game.add.group();
    //  This simply creates a sprite using the mushroom image we loaded above and positions it at 200 x 200
    test = game.add.sprite(200, 200, 'mushroom');
    test.inputEnabled = true;
    
    test.events.onInputDown.add(onClick, this);
    
    myGroup.add(test);

}

function onClick()
{
  myGroup.clear(true,true);
}

Rise 16.11.2019 04:51

Цитата:

Сообщение от Katy93
myGroup.clear is not a function

В Phaser 2 у класса Group нет метода clear(), он есть в Phaser 3. Нужно различать версии, примеры и документации:

https://phaser.io/docs/2.6.2 (Phaser 2)
https://photonstorm.github.io/phaser-ce (Phaser CE) >2.6.2
https://photonstorm.github.io/phaser3-docs (Phaser 3)

https://phaser.io/examples/v2 (Phaser 2 / CE)
https://phaser.io/examples/v3 (Phaser 3)

Цитата:

Сообщение от Katy93
Как сделать так, чтобы спрайт-картинка удалялась?

Пример с офсайта https://phaser.io/examples/v2/sprites/destroy


Архив версий https://phaser.io/download/archive


Часовой пояс GMT +3, время: 12:18.