Jump to content

player character group. hold different parts and move


charlieRobinson
 Share

Recommended Posts

Hello. n00by here.

I have a player character that I am moving around the screen using player.body.velocity.x= Z;   but I want to add a name above the player and a health bar. I come from actionscript where i would create a movieclip and add sprites to it and then move the movieclip to move the entire group.

I read about groups in phaser but I am not sure if this is the correct solution. if I make player a group and add playerChar(the sprite) and add the name text and health bar sprite, how do I move this group around? I can no longer use body.velocity

because that only applies to the player sprite and not the player group.  What is the best way to make a container to hold everything for the player and move it as a single unit? Thank you!!!!!

Link to comment
Share on other sites

27 minutes ago, iKest said:

Add  health bar sprite and name sprite directly to playerChar sprite as child


playerChar.addChild(healsBar);
playerChar.addChild(name);

They will move and rotate together with the parent sprite. Zero point for them will coordinates playerChar.

I thought for sure I tried this when I first started...

So add the health bar sprite to the player character sprite? and add the name text to the character sprite? I will try that again.

 

I thought I had to make an empty group and add all the pieces to that? hmm

Link to comment
Share on other sites

Quote

I thought I had to make an empty group and add all the pieces to that? hmm

Both Sprite and Group derives from PIXI.DisplayObjectContainer. This is reason, why you can add children to Sprite.

In case I need something bigger composed from parts like, one or more sprites, text, ... I usually create my custom class derived from Phaser.Group to keep things clean.

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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