Jump to content

Check for change sprite Phaser


Recommended Posts

You can check for any changes to any object in JavaScript by simply keeping a cached version of the property from the previous update, and comparing it to the current value. If the two differ, you can do something. Like so:

// set an arbitrary property on the spritesprite.happiness = 10;// create a cached copy of that propertysprite.lastHappiness = sprite.happiness;function update() {  // check to see if the current property differs from the cached version  if (sprite.happiness !== sprite.lastHappiness) {    // the sprite's happiness has changed so do something here  }  // update the cached version with the current version now all checks have been performed  sprite.lastHappiness = sprite.happiness;}
Link to comment
Share on other sites


  • Recently Browsing   0 members

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