Having some trouble with how if/else statement works. Im trying to do -
If my display object gets to 0 for Y and 0 for X then do this.
Im using a transition.to statement to move my object.
Any help appreciated. Thanks.
Having some trouble with how if/else statement works. Im trying to do -
If my display object gets to 0 for Y and 0 for X then do this.
Im using a transition.to statement to move my object.
Any help appreciated. Thanks.
Transition and if/else statements cannot be used together (I don’t know any simple method to do them together)
Could you explain in more detail what it is you are trying to do? Perhaps we could help you find a way to accomplish what it is you’re trying to do.
basically Im trying to create screen boundaries but I had plans to “fake” it by moving a display object with transition.to to upper left corner of the screen then back down with a second transition.to statement but so far it has not worked. I also, was hoping I could use a if then statement with a transition.to inside but I already tried that to no avail.
What if you position a rectangle in the left corner and check for collision with the object you are moving. If you get collision bounce the object back? I dont know if that would work but thats what I would try.
If you want to do something like this:
call transition.to( object, {x=200} ) (or any value) and in the same tame restrict movement to let’s say x = 180 ,
then unfortunately there is no easy elegant way.
Dirty one:
have enterFrame runtime checking for it … buuu…
Advanced one:
play with Lua metatables and create setter function for .x property - then there would be possibility to call just transition.to() and setter function would take care of keeping position bounds
I have scoured the net with no luck in finding a tutorial close to what im trying to do. Can anyone suggest a work around? This is the last part of my app, concerning functionality, that is left to complete. Any ideas?
Just a recap - my foreground object starts at the lower right of the screen and transition(s).to the upper left where instead of it going off the screen I need it to being to move back to the lower right, then loop over and over… Any help is greatly appreciated.
Tried transition.to and Runtime:addEventListerner to no avail.
First, try not to always rely on tutorials, instead think of the objective in it’s simplest form and formulate a method 
local upwardAnim, downwardAnim local toBottomRight, toTopLeft local circ = display.newCircle(0,0,50) circ.x = display.contentWidth - 50 circ.y = display.contentHeight - 50 function toBottomRight() downwardAnim = transition.to(circ, {x = display.contentWidth-50, y = display.contentHeight-50, time = 2000, onComplete = toTopLeft}) end function toTopLeft() upwardAnim = transition.to(circ, {x = 50, y = 50, time = 2000, onComplete = toBottomRight}) end toTopLeft()
Just suggestion: instead upwardAnim and downwardAnim I would just declare one ‘anim’, it’ll be simpler to stop or pause it.
If all you want to do is use a transition to move an object from one corner to another and back again, in an infinite loop, I really don’t know why you even need IF statements. I mean, it’s not like you don’t know when the object reaches 0,0… so you don’t need to check for that. You know it reaches 0,0 when the transition finishes…
-- transition help local circle = display.newCircle( 0,0,50 ) local trans local toBR, toTL toBR = function( obj, time ) trans = transition.to( obj, { time=time, x=display.contentWidth, y=display.contentHeight, onComplete=function() toTL( obj, time ) end } ) end toTL = function( obj, time ) trans = transition.to( obj, { time=time, x=0, y=0, onComplete=function() toBR( obj, time ) end } ) end toBR( circle, 2000 ) -- when you want to stop the infinite transitions, simply call this: -- transition.cancel( trans ) -- trans = nil -- but make sure you nil it afterwards
I thought I HAD to use an if statement… I’m still an amatuer. Among all the things in life that I can do well, programming has always been my “personal cryptonite”. I’m hoping to end that by learning corona sdk! Thanks for the post. I’m not understanding all of what the above does, but I’m gonna go play around in glider with it, right now. Thanks JonPM too, I’m gonna play with your posted sample code too. 
What in the code above do you not get? I can comment it, but it’ll mean more if you tell me what is confusing.
Transition and if/else statements cannot be used together (I don’t know any simple method to do them together)
Could you explain in more detail what it is you are trying to do? Perhaps we could help you find a way to accomplish what it is you’re trying to do.
basically Im trying to create screen boundaries but I had plans to “fake” it by moving a display object with transition.to to upper left corner of the screen then back down with a second transition.to statement but so far it has not worked. I also, was hoping I could use a if then statement with a transition.to inside but I already tried that to no avail.
What if you position a rectangle in the left corner and check for collision with the object you are moving. If you get collision bounce the object back? I dont know if that would work but thats what I would try.
If you want to do something like this:
call transition.to( object, {x=200} ) (or any value) and in the same tame restrict movement to let’s say x = 180 ,
then unfortunately there is no easy elegant way.
Dirty one:
have enterFrame runtime checking for it … buuu…
Advanced one:
play with Lua metatables and create setter function for .x property - then there would be possibility to call just transition.to() and setter function would take care of keeping position bounds
I have scoured the net with no luck in finding a tutorial close to what im trying to do. Can anyone suggest a work around? This is the last part of my app, concerning functionality, that is left to complete. Any ideas?
Just a recap - my foreground object starts at the lower right of the screen and transition(s).to the upper left where instead of it going off the screen I need it to being to move back to the lower right, then loop over and over… Any help is greatly appreciated.
Tried transition.to and Runtime:addEventListerner to no avail.
First, try not to always rely on tutorials, instead think of the objective in it’s simplest form and formulate a method 
local upwardAnim, downwardAnim local toBottomRight, toTopLeft local circ = display.newCircle(0,0,50) circ.x = display.contentWidth - 50 circ.y = display.contentHeight - 50 function toBottomRight() downwardAnim = transition.to(circ, {x = display.contentWidth-50, y = display.contentHeight-50, time = 2000, onComplete = toTopLeft}) end function toTopLeft() upwardAnim = transition.to(circ, {x = 50, y = 50, time = 2000, onComplete = toBottomRight}) end toTopLeft()
Just suggestion: instead upwardAnim and downwardAnim I would just declare one ‘anim’, it’ll be simpler to stop or pause it.