charlieRobinson Posted February 23, 2016 Share Posted February 23, 2016 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 More sharing options...
charlieRobinson Posted February 25, 2016 Author Share Posted February 25, 2016 any ideas? Still couldnt figure it out last night Link to comment Share on other sites More sharing options...
iKest Posted February 25, 2016 Share Posted February 25, 2016 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. Link to comment Share on other sites More sharing options...
charlieRobinson Posted February 25, 2016 Author Share Posted February 25, 2016 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 More sharing options...
Tom Atom Posted February 25, 2016 Share Posted February 25, 2016 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 More sharing options...
Recommended Posts