Sign in to follow this  

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;}

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.