Ball moves back and forth, from the left edge to the middle of the screen (without clock component)

Hello
It's the first time that I'm teaching app inventor.

In this page of "course in a box" there is a challenge that I can not solve.

http://www.appinventor.org/content/CourseInABox/drawAnimate/AnimationChallenge

In part 2 of challenge 4, it says:

"When a button is clicked, have ball 2 move back and forth, from the left edge of the screen to the middle of the screen and back, forever."

and because it is in continuation of challenge 2, it should be done without clock component. I can do it with while loop or some other complicated ideas, but it is in module 2 and before parts about loops and I don't have a simple idea for solving it.

Thanks

Set heading and speed

Thank you for your reply.

I set heading and speed, but I think anyway I need clock component for comparing x coordinate with the middle of the screen. How can I check it without clock component?

No clock needed (unless you need the x,y coordinates of the ball)

image

The middle of the screen, not the middle of the Canvas.

So put the canvas at the first slot of a left aligned horizontal arrangement and give it half the screen width.

Then it's just a matter of bouncing off the right edge with a bounce event.

If the canvas must be full width, put a Ball or sprite in the middle to collide with and reverse direction in the appropriate collision event..

1 Like

Better blocks from me (ABG's second suggestion)

Both Balls set to OriginAtCenter in the Designer

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.