Jump to content

Implementing Health Component on Sprites in 2.3


Akshar Patel
 Share

Recommended Posts

I noticed that with the 2.3 release, the health property and damage method have been moved to a separate Health Component. The problem is that I have no idea how to use it. Now, I know that it can easily be implemented manually, but I don't want to write code for things that are already implemented.  Can anyone help me understand how components work in phaser?

Link to comment
Share on other sites

Hey, just to make sure this gets answered: you don't really have to "use it", per se. Check out this code.

 

It iterates over the components and mixes in their prototypes via Phaser.Utils#mixinPrototype. That means that Phaser.Components.Core.update becomes the update method for whatever you install the component into. So, literally, Sprite's "update" method *is* the "update" method from the prototype of Phaser.Components.Core. Does that make sense?

 

Does that answer your question?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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