Make a image sprite bounce from left to right when it hits edge

Just wondering if there is a simpler way to make a sprite bounce left and right every time it hits the edge of a canvas. I have found one way but it is a little weird and doesn't always work right.

Show what you have achieved so far (your relevant blocks), perhaps someone here can help you with your coding/blocks.

To be clear, you want for a sprite, whenever it collides with any canvas edge, for the sprite to then move from left to right of the canvas, perpetually, and at what speed?

If you’re looking for linear motion, ie left to right and reversing it, or top to bottom and reversing it, then when the sprite collides with an edge just set its speed to -speed (ie negative speed).

1 Like

Have you tried the bounce block?

It gets the bounce angle right if hitting the edge diagonally.

Maybe I could try a timer that tells when it his a edge/wall if the second is even it bounces right or if it is odd it bounces left or vice versa and yes I have tried bounce blocks.

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

This is how i currently have it:
Screenshot 2022-09-25 8.36.51 PM

(Bouncer Left and Right are sprites)

"Boss_1" is also a sprite

Do not use collideWith event, but use ReachEdge event .

Okay, I deleted those blocks, here are my current relevant blocks:
Screenshot 2022-10-25 6.31.14 PM
They don't seem to be working when I test it, what could I fix?

Try a number instead of a list

From the documentation Drawing and Animation

Heading

The ImageSprite’s heading in degrees above the positive x-axis. Zero degrees is toward the right of the screen; 90 degrees is toward the top of the screen.

Taifun

1 Like

I could not successfully import the file :neutral_face:

Link works fine here. :slight_smile:
Something similar:

set up for Landscape orientation.