Jump to content

Creating a Health Bar | Attach graphic above sprite


liakos1992
 Share

Recommended Posts

A have attached a graphic (health bar) above a sprite like this:

// sprite is a 50x50 picturevar graphics = PH.add.graphics(10, 10);graphics.lineStyle(2, 0x0000FF, 1);graphics.beginFill(0x00FF08, 0.8);graphics.drawRect(-50, -50, 100, 10);sprite.addChild(graphics);

But when the sprite is rotated, the bar is rotated too. I want to attach it to be always above the sprite (around 50 distance) without attatching it manually at update() function

Link to comment
Share on other sites

If I understand well, you put your healthbar into the inner group of your sprite (the character?), so when you apply any change to the sprite its children are also affected. You might want to create a new group (not use the sprite's group) in which you'll put both the sprite and the healthbar, so when you apply changes to the sprite the healthbar will remain unaffected.

 

Or you can also do it without using groups, by adjusting the healthbar's x and y coords at each sprite's update :

char.update();healthbar.update(char.x, char.y);
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...