How to move a circle from left to right without touching the screen (on auto) ?

Hello,

I want a circle to move from the left to the right of the screen I tried to modify the “Oscillating objects” code but failed!  Can maybe someone help me out with this issue?

2

3

4

5

6

7

8

9

10

11

local needle = display.newRect( 100, 100, 10, 150 )

needle.anchorY = 0

needle.rotation = 50

 

local function moveNeedle()

    transition.to( needle, { tag=“moveNeedle”, time=1000, rotation=-50, transition=easing.inOutCubic } )

    transition.to( needle, { tag=“moveNeedle”, delay=1000, time=1000, rotation=50, transition = easing.inOutCubic } )

end

 

timer.performWithDelay( 2000, moveNeedle, 0 )

moveNeedle()

 

Thanks

Ari

Can you provide a better description of your goal? The code you provided seems to be working as a swing or metronome. But it’s not trying to move a circle across the screen.

Rob

Yes I know but this was the code I found in the same topic!

So I want a ball/circle to move from left to the right on auto like an enemy in a Jump game. I want my circle to stay on the y-axis but change it coordinates on the x-axis. ( a simple move from left to the right in a loop)

How do I get there I found some other links but they were only showing me the transition.to() option I tried also to modify this but it didn’t worked.

Could you maybe send me the code?

-Ari

There are many different ways to solve this. You can use transition.to. You can use physics. You can use a Runtime(“enterFrame”) event listener. Here is a simple AI module that a community member built:

http://simple-ai.blogspot.com/

Here are some tutorials:

https://coronalabs.com/blog/2015/08/25/tutorial-animation-with-enterframe-listeners/

https://coronalabs.com/blog/2015/08/18/tutorial-introduction-to-transitions/ (looks like this is where you got the above code from)

https://coronalabs.com/blog/2015/10/05/tutorial-physics-based-animation/

If you want help with the transitions based code, you will need to share with us what you’ve done, describe to us what you expect it to do and what you’re observing happening. 

When you share you code either type in:

[lua] ... paste your code here [/lua]

or click on the blue <> button in the editing options and paste your code in the window that pops up.

And we can advise from there.

Rob

Can you provide a better description of your goal? The code you provided seems to be working as a swing or metronome. But it’s not trying to move a circle across the screen.

Rob

Yes I know but this was the code I found in the same topic!

So I want a ball/circle to move from left to the right on auto like an enemy in a Jump game. I want my circle to stay on the y-axis but change it coordinates on the x-axis. ( a simple move from left to the right in a loop)

How do I get there I found some other links but they were only showing me the transition.to() option I tried also to modify this but it didn’t worked.

Could you maybe send me the code?

-Ari

There are many different ways to solve this. You can use transition.to. You can use physics. You can use a Runtime(“enterFrame”) event listener. Here is a simple AI module that a community member built:

http://simple-ai.blogspot.com/

Here are some tutorials:

https://coronalabs.com/blog/2015/08/25/tutorial-animation-with-enterframe-listeners/

https://coronalabs.com/blog/2015/08/18/tutorial-introduction-to-transitions/ (looks like this is where you got the above code from)

https://coronalabs.com/blog/2015/10/05/tutorial-physics-based-animation/

If you want help with the transitions based code, you will need to share with us what you’ve done, describe to us what you expect it to do and what you’re observing happening. 

When you share you code either type in:

[lua] ... paste your code here [/lua]

or click on the blue <> button in the editing options and paste your code in the window that pops up.

And we can advise from there.

Rob