Jump to content

Add variables and functions to group phaser


Recommended Posts

I created a group with the enemies on the screen. Now I would like to have each enemy hit points (some 2 others 3 others 4, etc ...). Then I thought that if there is way to make a kind of stretched groups phaser (and that he extended class could add a variable to the health points of each enemy ..?) 


Or do inthe Sprite class phaser .... I do not know how I should approach this. 


Any help or ideas? 



Link to comment
Share on other sites

Sprites already have a health property which you could probably use, though oftentimes it's better to create your own and manage it yourself. Extending Sprite is definitely the way to go. I'd definitely keep the hit points on the Sprites (or extended Sprite objects) and not the group, as the hit points count belongs to the enemies.

Link to comment
Share on other sites

There's an example of how to extend Sprite - you shouldn't edit phaser.js, just put this in your own file structure - usually with the rest of your game before the game code itself: http://examples.phaser.io/_site/view_full.html?d=sprites&f=extending+sprite+demo+1.js&t=extending%20sprite%20demo%201

Link to comment
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.


  • Recently Browsing   0 members

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