Jump to content

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


callidus
 Share

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 comment
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 comment
Share on other sites

 Share

  • Recently Browsing   0 members

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