Jump to content

How to set unique text on top of each group members sprite


Recommended Posts

I have a unique health value for each instance of a group, and I want to display it on the sprite as if it was a numeric health bar. 

 

Group object:

Here is where my group members are being created. I have an array that stores a randomly generated health value and assigns it to the array based on the member that was produced (currIndex starts at 0). So I want to somehow associate the health value stored in the array with the current member, and display this over top of the sprite. So each sprite member has a corresponding health value in the array. Is there a better way to associate this value with that particular instance of the sprite / display it onscreen over-top the sprite. 

function createBubble(xCoord, frame,value){
  bubbleInstance = bubbles.getFirstDead();
  bubbleInstance.reset(xCoord,0);
  bubbleInstance.anchor.setTo(0.5, 0.5);
  bubbleInstance.body.velocity.y = VELOCITY;
  bubbleInstance.frame = frame;

  //tracking the value of each bubble in an array
  BVALUES[currIndex] = value;
  currIndex++
}

 

Link to post
Share on other sites

I've tried adding the text like this:

function createBubble(xCoord, frame,value){
  bubbleInstance = bubbles.getFirstDead();
  bubbleInstance.reset(xCoord,0);
  bubbleInstance.anchor.setTo(0.5, 0.5);
  bubbleInstance.body.velocity.y = VELOCITY;
  bubbleInstance.frame = frame;

  //tracking the value of each bubble in an array
  BVALUES[currIndex] = value;
  currIndex++
  
  bubbleInstance.addChild(game.make.text(0,0,BVALUES[currIndex]))   //NEW LINE HERE
}

but I'm not sure how to handle changing the text. Lets say I have a function that handles the text change with setText, how should I refer to this instance of the text? 

Link to post
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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...