Hello, I created this script to subtract points to the score variable with the clockText.text variable. Anyone know what I can do for me subtract the total elapsed time whenever the ball lands, not the interval of one boat to another ?.
You can try the scrypt:
local physics = require "physics" physics.start() local score = 500 -------------------------------------------Initial Time-------------------------------------------------------- local initialtime = display.newText(score, 100, 200, "Helvetica", 40) -------------------------------------------Accountant-------------------------------------------------------- local clockText = display.newText("000", 100, 300, "Helvetica", 40) local secondsLeft = 0 -- secons local function updateTime() secondsLeft = secondsLeft + 1 seconds = secondsLeft % 60 timeDisplay = string.format("%03d", seconds ) clockText.text = timeDisplay end countDownTimer = timer.performWithDelay( 1000, updateTime, secondsLeft ) -------------------------------------------Collision--------------------------------------------------------- local platform = display.newRect( 0, 0, 280, 30 ) platform.surfaceType = "superbounce" platform.x, platform.y = display.contentCenterX, display.contentCenterY+200 physics.addBody( platform, "static", { bounce=0.0, friction=0.3 } ) local ball = display.newCircle( 0, 0, 15 ) ball.x, ball.y = display.contentCenterX+100, display.contentCenterY-40 physics.addBody( ball, "dynamic", { bounce=0.0, radius=20 } ) local function onCollision( self, event ) local collideObject = event.other if ( collideObject.surfaceType == "superbounce" ) then event.contact.bounce = 1 print(score - clockText.text) initialtime.text = score - clockText.text end end ball.collision = onCollision ball:addEventListener( "collision" )