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

Create and Destroy Sprites Using Functions


Larry
 Share

Recommended Posts

I'm trying to create platforms for my player to jump onto and also make collectible stars. I can create these sprites using functions, but I don't know how to make physics work on them so that the character can jump on the platforms and overlap with the stars. The problem is that the physics portion doesn't work when I call it in the update function. I am also not using tilesprites, so it can't work that way.

 

create: function() {
    addStar(star1);
},
update: function() {
    removeStar(star1);
}

addStar(name) {
    name = game.add.sprite(1700, 550, 'star');
    name.anchor.setTo(0.5, 0.5);
    this.game.physics.enable(name, Phaser.Physics.ARCADE);
    name.body.collideWorldBounds = false;
    name.enableBody = true;
    name.body.immovable = true;
}

removeStar(name) {
    if (game.physics.arcade.overlap(character, name) == true) {
        name.destroy();

        updateScore();
    }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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