I want to show each player’s health above it’s head (above the sprite itself). I dynamically create players thus want to create bars dynamically aswell, but i can’t figure out a way to associate a health bar to a player.
I mean, i create a player for example…
players = {}
local character = display.newSprite( myImageSheet , sequenceData )
character.health = 100
players[#players + 1] = character
Now i have my code for the health bar which is like this…
healthRect = display.newRect(0,0,100,10) healthRect:setFillColor(0,255,0) healthRect:setReferencePoint(display.TopLeftReferencePoint) if(player.health\>50)then healthRect:setFillColor(0, 255, 0) elseif(player.health\<=50 and player.health\>20)then healthRect:setFillColor(255, 255, 0) elseif(player.health\<=20)then healthRect:setFillColor(255, 0, 0) end healthRect.width = player.health healthRect.x = player.x healthRect.y = player.y - (player.height/2) - 20
If there was only one player i could use something like above but since there will be multiple players each created dynamically, how do i associate each health bar to the specific player?
Thanks Alot!