Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Multiple images moving different directions

1. I have found this

Code:
```with instance_create(
x+lengthdir_x(80,image_angle),
y+lengthdir_y(80,image_angle),obj_bullet)
{
xspeed=lengthdir_x(10,other.image_angle)
yspeed=lengthdir_y(10,other.image_angle)
}```
or this one

Code:
```with instance_create(
x+lengthdir_x(80,image_angle),
y+lengthdir_y(80,image_angle),obj_bullet)
{
xspeed=cos(other.image_angle*pi/180)*10     //convert degrees to radians when using these
yspeed=-sin(degtorad(other.image_angle))*10 //i think the y component needs to be flipped
}```
but I can't match it with your code.

2. *sigh*

Okay look at that code:
Code:
```if ( x==0 || x==xmax || y==0 || y==ymax )
{
bug.xspeed = - bug.xspeed;
bug.yspeed = - bug.yspeed;
}```
That can be read as "if EITHER the x or y position reaches EITHER the smallest or largest allowed value, then reverse the direction of BOTH the x and y movement."

CLEARLY that is NOT what you want. You want to reverse the x direction if x reaches the limits and *separately* reverse the y direction if y reaches the limits.

So very very simply:
Code:
```if ( x==0 || x==xmax )
{
bug.xspeed = - bug.xspeed;
}
if ( y==0 || y==ymax )
{
bug.yspeed = - bug.yspeed;
}```
TRY IT!

3. thank you, it works perfectly.

I will learn javascript one day, I promise.

4. Now where in the world did you find that picture of me?

Of course, that was taken some time ago, while I still had a little hair on my head. (On the back; it doesn't show in that picture.)

<grin/>

5. // find one
var bugimg = document.getElementById("bug"+bugnum);
if ( bugimg == null ) break; // but stop when no more to be found

// don't allow position to be out of bounds
if ( x < 0 ) x = 0;
else if ( x > xmax ) x = xmax;
if ( y < 0 ) y = 0;
else if ( y > ymax ) y = ymax; ( I want to remove this part because all the images flow away and come back to what is seen.

Q1: how can I make all the images keep flowing continuously?

Page 3 of 3 First 123

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•