Guys i need help.
I want the “delay” to decrease when “5” crates collides with the grass so that it would be a lot faster to create more crates. But its not working. And its not either showing any errors, but it shows the text on the simulator “Decreasing delay at 0.5 second.” .
Here’s my code.
<code>
function scene:enterScene( event )
local group = self.view
physics.start()
local NumOfCrates = display.newText( “0”, 0 , 0 , “Calibri”, 24 )
NumOfCrates:setTextColor (255,255,255)
NumOfCrates:setReferencePoint( display.TopRightReferencePoint )
NumOfCrates.x = display.contentWidth - 30
NumOfCrates.y = 20
NumCrates = 0
–As the Crate collides with the grass, it counts how many crates collided.
function CollisionCrate (self, event)
if (event.phase == “began”) then
NumCrates = NumCrates + 1
NumOfCrates.text = NumCrates
end
end
local GrassAp = display.newImage (“grass.png”)
GrassAp.alpha = 1
GrassAp.alpha=0
transition.to(GrassAp,{alpha=1,time=500})
GrassAp.y = 500
GrassAp.rotation = 180
physics.addBody (GrassAp, “static”,{ friction=0.5, bounce=0.3,isSensor = true })
GrassAp.collision = CollisionCrate
GrassAp:addEventListener (“collision”,GrassAp)
local crates = 0
local dTime = 1500
local FallingCrates
function spawnCrate(event)
Crate1 = display.newImage (“crate.png”);
Crate1.x = 70 + math.random(155)
Crate1.y = -20
Crate1.rotation = 1
physics.addBody (Crate1, {density=0.3,bounce=0.5,friction=0.5})
physics.setGravity (0,4)
–This is the code which I think is not working. But the " print (“Decreasing delay at 0.5 second.”) " can be seen in the simulator. But dTime is not changing at all.
if NumCrates == 5 then
dTime = 500
print (“Decreasing delay at 0.5 second.”)
end
end
FallingCrates = timer.performWithDelay (dTime,spawnCrate,crates)
print( “Game: enterScene event” )
end
<code>
Thanks in advance guys.

