Moving objects without using physics?

Okay, I just tried to place it here… ChangeForeGround() is located at line 30 ( see previous post )

ChangeForeground() transition.to ( foreground, { time=10000, x=0, y=0}) timer.performWithDelay(10000, ChangeForeground, -1)

and it works the first time, but when the background and foreground update it does not animate anymore…Any suggestions? It’s a real shame the runtime event keeps speeding up on me, other than that problem it works perfectly…

ChangeForeground() transition.to ( foreground, { time=10000, x=0, y=0}) timer.performWithDelay(10000, ChangeForeground, -1)

Programs execute in a linear method from top to bottom unless they are redirected using conditional statements like “if” statements or looping elements like “while” loops.

If you read your program, these three statements.  Basically this is what happens:

  1. Your ChangeForeground function is called once.
  2. Your transition.to is performed once.
  3. You execute a reoccuring timer every 10 seconds that calls your ChangeForeground function again and again.

At no point do you instruct your program to execute the transition.to more than once.  I would consider moving the transition.to into your ChangeForeground function and replace this code:
 

local function animateFG (event)   foreground.y = foreground.y -0.1 foreground.x = foreground.x -0.1   end Runtime:addEventListener ("enterFrame",animateFG)

Of course your transition.to also needs to move your .y as well.

Okay I had to take a little break from coding, but this works -

ChangeForeground (transition.to ( foreground, { time=9000, x=0, y=0 }))

Thanks for describing everything. Sometimes frustration sets in to a point where Im not actually angry, but my brain starts to fumble and I start to perpetually make mistakes, etc. It’s the beginning of “angry”, lol…

Anyway, what I mean is, I appreciate being able to learn (from the sample code given) as opposed to only getting a answer. Thanks again for describing all that. B)

Instead of starting a new post, I’ll just ask here…

I have a runtime event that positions my image on the screen. How would I animate it from say point A to Point B over a period of 3 seconds using the runtime event?

It would be easier to use a transition.to() call and not do it with a Runtime enterFrame listener, but . . .

You would need to know the distance of A to B.  Lets say A.x is 100 and B.x is 400.  The distance is 300.

d = B.x - A.x – i.e 300

t = 3 – seconds

frames = t * 30 – 30 fps, if your a 60fps app change it to 60

distancePerFrame = d / frames

A.x = A.x + distancePerFrame

or something like that.

Thanks I will try it out. And just for the record, I have tried transition.to method but I cant get it to work for some reason. I dont get an error, I just get no animation…Strange.

I may be putting the transition.to statement in the wrong place, but I have tried moving it around in different parts of my code and still get no animation. Like I said, no error but no animation either.

Without seeing some code, it’s hard to tell what is going on.  I can tell you with 100% certainty that transition.to works and works well in the build you are using (I’m assuming you are using 1202).  We just updated the transitions library in the daily builds and are ironing out a couple of backwards compatible issues.

Post some code where your  transition.to’s are not now working.

Okay, well here’s what I’m working with. I DID get things working with a runtime add event listener, but it doesnt work right. It actually gains speed over time, which is not what I was hoping would happen. See below.

local fNames = {"images/fg1.png","images/fg2.png","images/fg3.png"} local foreground = nil math.randomseed(os.time()) local function ChangeForeground() if foreground then foreground:removeSelf() foreground = nil end local imageNameFG = fNames[math.random(1, #fNames)] foreground = display.newImage(imageNameFG) foreground.isVisible = true foreground:setReferencePoint ( display.CenterReferencePoint ) foreground.xScale = .325 foreground.yScale = .325 foreground.x = 420 -- could also use display.contentWidth foreground.y = 500 -- could also use display.contentHeight local function animateFG (event) foreground.y = foreground.y -0.1 foreground.x = foreground.x -0.1 end Runtime:addEventListener ("enterFrame",animateFG) end ChangeForeground() timer.performWithDelay(10000, ChangeForeground, -1) --end FOREGROUND ; begin next -----------------

The part that says “foreground.y = foreground.y -0.1
foreground.x = foreground.x -0.1”  at lines 23, etc., just above the runtime add event listener works okay in the beginning but over time it keeps speeding up, which I dont want…That’s the only problem, otherwise it DOES work…

I would rather use a transition.to, but like I said it just doesn’t want to work for me… What I’m doing wrong concerning the transition.to, I just have no clue…

Can you post the code where you’re trying to use transition.to?

I have tried using it all the place in that code, if I dont get an error, I get no animation. So the transition.to statement either generates an error or it just does nothing at all…But I have placed it all over, and also tried changing the table/function call that I put inside the transition.to statement…all to no avail.

I don’t know what you’re trying to move or where the best place to do it is, but the core transition.to is:

local z = display.newRect(0,0,100,100)
transition.to(z, { time=1000,  x=200})

Can you try that and make sure it works for you?

Im trying to move the random display objects towards the top of the code (fg1, fg2, etc.).

I was using transition.to { z, time=500, x=0, y=0}

Maybe I was typing the statement wrong? I’ll give yours a try.

Nope. I get loads of errors when I try to place it anywhere. I have tried substituting “z”, for fNames, foreground, and a few others to no avail… If you want to see the error just ask I will post it but I dont see how it would help me at this point…

we really need to see the errors…  and the code.

Okay, I just tried to place it here… ChangeForeGround() is located at line 30 ( see previous post )

ChangeForeground() transition.to ( foreground, { time=10000, x=0, y=0}) timer.performWithDelay(10000, ChangeForeground, -1)

and it works the first time, but when the background and foreground update it does not animate anymore…Any suggestions? It’s a real shame the runtime event keeps speeding up on me, other than that problem it works perfectly…

ChangeForeground() transition.to ( foreground, { time=10000, x=0, y=0}) timer.performWithDelay(10000, ChangeForeground, -1)

Programs execute in a linear method from top to bottom unless they are redirected using conditional statements like “if” statements or looping elements like “while” loops.

If you read your program, these three statements.  Basically this is what happens:

  1. Your ChangeForeground function is called once.
  2. Your transition.to is performed once.
  3. You execute a reoccuring timer every 10 seconds that calls your ChangeForeground function again and again.

At no point do you instruct your program to execute the transition.to more than once.  I would consider moving the transition.to into your ChangeForeground function and replace this code:
 

local function animateFG (event)   foreground.y = foreground.y -0.1 foreground.x = foreground.x -0.1   end Runtime:addEventListener ("enterFrame",animateFG)

Of course your transition.to also needs to move your .y as well.

Okay I had to take a little break from coding, but this works -

ChangeForeground (transition.to ( foreground, { time=9000, x=0, y=0 }))

Thanks for describing everything. Sometimes frustration sets in to a point where Im not actually angry, but my brain starts to fumble and I start to perpetually make mistakes, etc. It’s the beginning of “angry”, lol…

Anyway, what I mean is, I appreciate being able to learn (from the sample code given) as opposed to only getting a answer. Thanks again for describing all that. B)