Hi friends. Im completely new to Lua. I used to program back in the day with C++ but its been a while. Please don’t mind the absolute stupid questions below and in the future.
I went through the first chapter and got the simple balloon thing working. Great. Now, I wanted to add a bit more to that like a “Loss counter”
The idea is that every time the balloon hits the platform the tapCounter resets and the losCounter goes up.
Can someone help? I tried this code in red below but im pretty sure im not referencing the right properties.
local tapCount = 0 local losCount = 0 local background = display.newImageRect("background.png", 360, 570) background.x = display.contentCenterX background.y = display.contentCenterY local tapText = display.newText( tapCount, display.contentCenterX, 20, native.systemFont, 40 ) tapText:setFillColor( 0, 0, 0 ) local winText = display.newText(winCount, 30, 20, native.systemFont, 40 ) winText:setFillColor( 0, 255, 0 ) local losText = display.newText(winCount, 290, 20, native.systemFont, 40 ) losText:setFillColor( 255, 0, 0 ) local platform = display.newImageRect( "platform.png", 300, 50 ) platform.x = display.contentCenterX platform.y = display.contentHeight-25 local balloon = display.newImageRect( "balloon.png", 112, 112 ) balloon.x = display.contentCenterX balloon.y = display.contentCenterY balloon.alpha = 0.8 local physics = require( "physics" ) physics.start() physics.addBody( platform, "static" ) physics.addBody( balloon, "dynamic", { radius=55, bounce=0.3 } ) local function pushBalloon() balloon:applyLinearImpulse( 0, -0.75, balloon.x, balloon.y ) tapCount = tapCount + 1 tapText.text = tapCount if ( balloon.y == platform.y ) then losText = losText + 1 tapCount = 0 end end balloon:addEventListener( "tap", pushBalloon )