Level Counter

I’m trying to stick a level/lives counter into my game. I already have coding to update the variables, but I’m not sure how to update the display object. Can anyone help? [import]uid: 100403 topic_id: 20968 reply_id: 320968[/import]

See:

http://omnigeek.robmiracle.com/2011/05/30/implementing-a-health-status-bar-in-corona-sdk/

for how to do a lives counter.

Not sure how you want to display the level, but if its just showing the number, you can use a display.newText() object to create a text object on the screen:

local levelText = display.newText(string.format("Level %d",level),0,0,"Helvetica",32)  
levelText:setReferencePoint(display.TopLeftReferencePoint)  
levelText.x = 0  
levelText.y = 0  

then later when you want to change it

levelText.text = string.format("Level %d",level)  

[import]uid: 19626 topic_id: 20968 reply_id: 82786[/import]

Thanks, that helps me a ton.

However, I’ve found that the game often uses two lives at once. The player taps to respawn the character, and unless the player taps extremely quickly two or more lives are used up. Is there anyway to set a delay to keep this from happening? Not sure if there is an equivalent in Lua to C++'s sleep(1.0) command. [import]uid: 100403 topic_id: 20968 reply_id: 82789[/import]

There really isn’t a sleep command. There is a timer.performWithDelay(ms, functionToExecute, [optional number of times])

which can do some delayed actions.

Can you post your code around the tap action?

I suspect you may have a touch event listener on the player and touch generates two events on a tap. A began event and an ended event. If you’re not checking for what phase of the touch event you are in, you’re code can execute twice.

[import]uid: 19626 topic_id: 20968 reply_id: 82795[/import]

Thanks, I was able to fix the problem by only subtracting the lives after the touch event ended. [import]uid: 100403 topic_id: 20968 reply_id: 82802[/import]

Glad to hear you got it fixed.

[import]uid: 84637 topic_id: 20968 reply_id: 82812[/import]