Jump to content

Phaser reset sprite


PhasedEvolution
 Share

Recommended Posts

Hello. I have created a function that instances a sprite giving attributes such as phyisics and size , etc. In the end of the function I kill the sprite. I put a keyboard input that when clicked resets that sprite to the given coordinates. I am using the isometric plugin. However the reset happens the sprite image doesn't appear. I see the body if I debug it. However no collision is happening as well. I only see the cube. If I spawned it normally the image sprite image would appear and I could collide with it. Any idea my sprite has no image and seems to don't collide with anything? Probably it is something related to phaser in general and not with the iso plugin

Link to comment
Share on other sites

15 hours ago, lumoludo said:

If you are calling kill() on it, are you calling revive() on it when you want to use it again?

No ^^ I didn't even know it existed really. Thank you. I thought reset was already responsible for reviving...  Can I specify coordinates where to revive ? I could specify them when using reset... I have this code. I can spawn it again but after spawning once it doesnt reset its position to the new position ( my dude.body position changes)...

 

function chair_wall () {

   chair_wall = game.add.isoSprite(200,200,0,'chair_wall',0,random_sprites_group);
   game.physics.isoArcade.enable(chair_wall);
   chair_wall.body.collideWorldBounds = true;
   chair_wall.kill();

}

chair_wall();


//assigned a button to spawn it after when needed

  add_chair_wall.onDown.add (function () {
        
          // I tried checking if it is alive and killing if it is and then reset 



            chair_wall.reset(dude.body.x,dude.body.y,0);
            

   
 
        }) 

 

Link to comment
Share on other sites

I don't think so. Functions should really only be meant to do one thing, and revive()'s job is just to bring a kill()'ed object back into existence. You should be able to just set the X and Y coordinates manually after you revive it, or if you wanted to, you could write your own function to revive() and set the position of a sprite.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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