Reputation: 845
I am creating a game where there are a lot of egg images dropping down and there are randomly generated numbers displayed on them. When the eggs are tapped, I need to retrieve the number associated with it. The following is my code
local myRandomNumber = math.random(0,10)
local egg=display.newImage("egg.jpg")
egg.numberValue=myRandomNumber
Right now I have the number associated to the egg image, but I wanted the numberValue(i.e the random number generated) to be displayed on the image. How can I achieve this?
Upvotes: 1
Views: 73
Reputation: 664
Here is sample code to do so. Add it below Your code.
local eggText = display.newText({x = egg.x, y = egg.y, text = tostring(egg.numberValue), fontSize = 15, font = native.systemFont })
eggGroup :insert(egg)
eggGroup :insert(eggText)
Then just do transition on eggGroup instead of on 'egg'
Upvotes: 2