callidus Posted April 25, 2020 Share Posted April 25, 2020 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 More sharing options...
callidus Posted April 25, 2020 Author Share Posted April 25, 2020 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 More sharing options...
Imrryran Posted April 26, 2020 Share Posted April 26, 2020 You should keep a reference on the child text object, and modify its content, not the js text string object itself. callidus 1 Link to comment Share on other sites More sharing options...
callidus Posted April 27, 2020 Author Share Posted April 27, 2020 On 4/26/2020 at 9:27 AM, Imrryran said: You should keep a reference on the child text object, and modify its content, not the js text string object itself. I see thank you this worked, I was over-complicating the problem in my head Imrryran 1 Link to comment Share on other sites More sharing options...
Recommended Posts