Good day all,
For platform game, we can always see a movement platform
eg. from left to right, then to left again
I wonder how can we code out a left…right…left… movement using transition.to?
Thanks for the guiding [import]uid: 10373 topic_id: 4677 reply_id: 304677[/import]
[lua]-- keep a table of active transitions
local transitions = {}
– create objects
local platform1 = display.newImage(“platform.png”)
local platform2 = display.newImage(“platform.png”)
– forward reference to functions
local goLeft
local goRight
function goRight(obj)
transitions[obj] = transition.to(obj, {time=1000, obj.x+200, onComplete=goLeft})
end
function goLeft(obj)
transitions[obj] = transition.to(obj, {time=1000, obj.x-200, onComplete=goRight})
end
goRight(platform1)
goRight(platform2)[/lua]
then when you want to cancel all movement just iterate over the “transitions” table and do .cancel() on each item
[import]uid: 6645 topic_id: 4677 reply_id: 14812[/import]
note that you have to test their collision too, if not your character would just fall through, well maybe not fall through since you are not using physics
Also, search for beebeegames , it has pause capability [import]uid: 11334 topic_id: 4677 reply_id: 14856[/import]
i found corona strange behavior,
which mean u need to have the function visible before u call them.
For example your case,
function goRight(obj)
transitions[obj] = transition.to(obj, {time=1000, obj.x+200, onComplete=goLeft})
end
can never call goLeft coz it’s at bottom.
What i resolve my moving leftright action, is i have the same function calling itself, using a global 12 variable swap to call different transition.to
Thanks for the idea! [import]uid: 10373 topic_id: 4677 reply_id: 14872[/import]
You can call goLeft from goRight (and vice versa) because I already defined the forward references above both of them [import]uid: 6645 topic_id: 4677 reply_id: 14894[/import]