How do I get the direction of a moving sprite?

Get help using Construct 2

Post » Tue Jun 24, 2014 10:58 pm

I need to evaluate the current direction of a moving sprite, so that I can set the correct animation chosen from an 8-directional set of animations.

I have searched the forum and the manual for help, but can't seem to find the info.

I know it must be possible, its a very basic requirement. :)

I have attached a capx of my test file.

Also below is a snapshot of what I was trying to achieve using the "angle" expression before I realised it wasnt the right approach.
Image

Any help appreciated :)
You do not have the required permissions to view the files attached to this post.
B
6
S
1
Posts: 41
Reputation: 482

Post » Tue Jun 24, 2014 11:32 pm

What you are looking for is the property MovingAngle. It's a property both of the Platform and 8Direction behaviors and you access it by looking inside behavior properties. For instance, if your avatar is called PlayerAvatar, the property would be PlayerAvatar.Platform.MovingAngle (or PlayerAvatar.8Direction.MovingAngle in case you're using this behavior).

You can check a working example at the url below:
http://www.gamesintheattic.com/examples/directions/

Move the dog to all 8 directions using the arrows, the MovingAngle property is shown on the top left corner.

Your code seems to be ok. However, I prefer to have an invisible object called player, which I control directly, and have another object, called avatarAnimations, which contains all animations, pinned to it.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
16
S
4
G
1
Posts: 435
Reputation: 2,353

Post » Wed Jun 25, 2014 6:31 am

OK that's great thank you. :)

What is the benefit of pinning an invisible character to an animated sprite over just animating the sprite directly?

Thanks again
B
6
S
1
Posts: 41
Reputation: 482

Post » Wed Jun 25, 2014 7:17 am

I have just found the "direction" property in the gridmove function! :D My next step will be trying to get gridmove to work diagonally...

For the benefit of anybody that needs to know how to do this in future, using the Grid_MoveTO function, I have shown the event below:

Image
B
6
S
1
Posts: 41
Reputation: 482

Post » Wed Jun 25, 2014 2:37 pm

revvin wrote:OK that's great thank you. :)

What is the benefit of pinning an invisible character to an animated sprite over just animating the sprite directly?

Thanks again


To be honest, I can't remember why I started doing it, but it was related to an animation problem I had. :)
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
16
S
4
G
1
Posts: 435
Reputation: 2,353

Post » Wed Jun 25, 2014 7:04 pm

lol fair enough. i'll probably stumble across that issue one day... at least i'll know a workaround. :)
B
6
S
1
Posts: 41
Reputation: 482


Return to How do I....?

Who is online

Users browsing this forum: amazingdream, Yahoo [Bot] and 20 guests