# Direction of a sprite

Get help using Construct 2

### » Tue May 29, 2012 9:25 am

Hello,

How to know the direction of an object?
I want to make a game where enemies move freely but I don't detect the direction of the sprite to change the animation

anyone know how to do?
B
4
Posts: 10
Reputation: 395

### » Tue May 29, 2012 12:52 pm

In Construct2, "direction" is called "angle." An angle of 0 means the sprite is moving to the right, and 180 means it is moving to the left, etc. You can use a sprite's "is between angles" event to detect its current angle/ direction.
B
16
S
4
G
1
Posts: 40
Reputation: 2,705

### » Tue May 29, 2012 1:11 pm

thanks! but if the enemy moves in 4 directions?
If the sprite goes in horizontal direction and rotates clockwise, the sprite will change the animation to go down or up but if the sprite walks in the vertical direction and rotate to the right will change the animation to walk to the right or left.
How is that done?
The sprite can be rotated at the same angle but depending on the direction that has the sprite animation can be different

thanks!
B
4
Posts: 10
Reputation: 395

### » Tue May 29, 2012 1:46 pm

You can always detect the sprite's angle of movement, so then it is just a matter of selecting the animation that goes with that angle. If you have four animations which you name left, right, up, down, and the sprite's angle is 180, then you set the animation "left" for the sprite. If the sprite's angle is 90, then you set the animation to "down" and so on.
B
16
S
4
G
1
Posts: 40
Reputation: 2,705

### » Tue May 29, 2012 2:06 pm

Hello,
I did what you say but the sprite does not rotate.
I want that when it collides with the arrow sprite changing direction and animation but does not.only changes the direction not the animation. Sure you do something wrong..
let the example
https://www.dropbox.com/s/7u0fgjpzwwd3qz7/pac.capx

Thanks!
B
4
Posts: 10
Reputation: 395

### » Tue May 29, 2012 3:17 pm

Since your animations are just single frames, there may be easier ways to flip between the images. In fact, if the sprite has the bullet behavior, you can rotate the sprite image to the angle of movement. You don't do this with an event, but in the bullet behavior properties. Here is a demo capx. (Note, I created this with the latest release, v.92, that came out yesterday. So you need r92 to run it.)

http://dl.dropbox.com/u/6109058/ChangeDirDemo.capxjimand2012-05-29 15:24:38
B
16
S
4
G
1
Posts: 40
Reputation: 2,705

### » Tue May 29, 2012 3:28 pm

Here is a modified demo, in which clicking the mouse changes the direction and image by 90 degrees.

http://dl.dropbox.com/u/6109058/ChangeDirDemo2.capx
B
16
S
4
G
1
Posts: 40
Reputation: 2,705

### » Tue May 29, 2012 3:57 pm

I made ??the changes you told me . He behavior fantasma al bullet change direction rotates the image but does not change to another animation simply rotates the principal image .Later, the game will have more complex animations
https://www.dropbox.com/s/7u0fgjpzwwd3qz7/pac.capx

thanks!
B
4
Posts: 10
Reputation: 395

### » Tue May 29, 2012 8:59 pm

Maybe this thread will help you. There are two different versions -- the original one switches the animation frame based on the angle of the sprite and the second one switches the animation itself, not just the frame.

Change Frames like Compass Sprite in 8dirkittiewan2012-05-29 21:00:40
B
30
S
12
G
13
Posts: 281
Reputation: 12,428

### » Wed May 30, 2012 10:06 am

ok thanks! It has given me a great idea to pursue the enemy sprite to the player
B
4
Posts: 10
Reputation: 395

Next