Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Error when removing a sprite from a group


garethquirke
 Share

Recommended Posts

I

've been following this example on the phaser website https://github.com/photonstorm/phaser-examples/blob/master/examples/groups/remove.js

I get the error "Cannot read property 'visible' of undefined" when I remove one of the flasks from the list, I can't seem to see the problem in my code.

let gameState = {
preload: function () {
    // new game elements : flask and big flask
    game.load.image('flask', '/GameHub/Assets/flask.png',40,40);
    game.load.image('bigflask', '/GameHub/Assets/bigflask.png',180,180);
    game.load.image('rectangle', '/GameHub/Assets/rectangle.png');
},
create: function () {
    game.stage.setBackgroundColor(0xFFFFFF);
    items = game.add.group();
    var item;
    for (var i = 0; i < 4; i++) {
        item = items.create(90, 16 + 90 * i, 'flask', i);
        item.name = 'flask' + i;
        item.inputEnabled = true;
        item.input.enableDrag();
        item.input.enableSnap(90, 90, false, true);
        item.events.onDragStop.add(dropFlask, this);
    }
    var rectangle = game.add.sprite(390, 20, 'rectangle');
    rectangle.scale.setTo(2.0, 3.0);

    var number = game.add.text(570, 30, '0');
    var flask5 = game.add.sprite(490, 130, 'bigflask');
}

And my drop function as follows:

function dropFlask(item, pointer) {
if (item.x < 90) {
    item.x = 90;
}
else if (item.x > 390){
    items.remove(item);
}}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...