Hi, I want to make my bg scroll down and be replaced by a 2nd bg that I've positioned directly above the 1st. I've got a draggable object (my player) that I want to trigger the scrolling movement when it hits the top of the screen. I figure I need to write some sort of code like
1 2 3 4 5 6 7 8 9 10 | local function wrap (event) if player.y < 50 then player.y = 50 --add some sort of "move bg's and player 480 pixels down" command-- end end Runtime:addEventListener("enterFrame", wrap) |
I guess you mean scrolling form top to bottom. If that's true, you may want your 2nd bg "minus" 480 instead of plus.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | --first place your bg2 480 pix above bg1 bg2.y = bg1.y - 480 if player.y < 50 then player.y = 50 -- you may want to do something with the eventlistener for the player's here player.y = player.y + 380 bg1.y = bg1.y + 480 bg2.y = bg2.y + 480 end -- OR make it move smoothly if player.y < 50 then player.y = 50 -- you may want to do something with the eventlistener for the player's here transition.to(player, {time = 395, delay = 0, y = player.y + 380}) transition.to(bg1, {time = 500, delay = 0, y = bg1.y + 480}) transition.to(bg2, {time = 500, delay = 0, y = bg2.y + 480}) end |
Thanks Dan300, this looks like what I'm after. I'll give it a try.
Cheers,
Steven
@Dan300 Your code worked great, thank-you. More impressively, you're spot on with your notes, turns out I do indeed want to do something with the eventlistener for the player where you indicated. As you forsaw, it looks funny to have the player zipping back and forth while the backgrounds are transitioning (not to mention the player snapping to the user's finger once the transition is done). I need to take control away from the user while this transition takes place. So now the question is: how do you temporarily cancel an event? I tried inserting
1 | event.phase = "cancelled" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | if "moved" == event.phase then if player.y < 50 then -- add the listener back after 0.5 sec timer.performWithDelay(500, function(event) player:addEventListener( "touch", NameOfYourListener ) end, 1 ) -- remove the listener for now player:removeEventListener( "touch", NameOfYourListener ) -- add scrolling movement code here return end elseif "ended" == event.phase or "cancelled" == event.phase then end |
@Dan300 Worked perfectly. You're a pro.
Much thanks,
Steven
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
Reflexic now available in the iTunes store
How this app can be created through Corona?
Reset Score [RESLOVED]
whats the best way to combine two tables
Problem translating a table of images
Corona 2.0 Beta 5 now available for download
Audio and Device Volume Settings
Little Ball - First game with Corona
Overlapping button objects issue