Hello guys, I have to change the scene after a collision, and I did it using the following code:
function onCollision( event )
if ( event.phase == "began" ) then
if event.object1.myName == "coin" and event.object2.myName == "player" then
event.object1.alpha = 0.001
director:changeScene("second")
player:removeSelf()
player = nil
bgSpeed = 0
local fade = display.newImage("immagini/fade.png")
fade.alpha = 0
transition.to( fade, { alpha=1, time=1000 } )
media.playSound( "suoni/newworld.wav" )
end
elseif ( event.phase == "ended" ) then
if event.object1.myName == "coin" and event.object2.myName == "player" then
event.object1:removeSelf()
event.object1 = nil
end
end
end
Runtime:addEventListener( "collision", onCollision )
Well, the scene change, the problem is that it remain static with all the object fixed on the screen, while they should move.
I thought it was a problem of the scene I changed, so I created a very simple scene with a transition, but unfortunately it still won’t work.
Here’s the simple scene I created for test purposes:
local director = require "director"
r = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
r:setFillColor( 255, 255, 255 )
local function repeatFade (event)
r.alpha = 1
transition.to( r, { alpha=0, time=1000 } )
end
timer.performWithDelay(1000, repeatFade, 20 )
any ideas on I can I fix my problem?
Thanks!
[import]uid: 122056 topic_id: 34188 reply_id: 334188[/import]
[import]uid: 122056 topic_id: 34188 reply_id: 135988[/import]