How do I go to one frame forward or one frame back?

Get help using Construct 2

Post » Sun Jul 19, 2015 7:53 pm

I have a cannon that needs to rotate on a pivot. Each side is a different picture, so on pressing left or right, I need the animation to know to go forward or back one frame. Thanks!
B
5
Posts: 37
Reputation: 299

Post » Sun Jul 19, 2015 8:13 pm

You can use this string:

self.animationframe+1
and
self.animationframe-1
B
52
S
22
G
12
Posts: 725
Reputation: 11,716

Post » Sun Jul 19, 2015 8:22 pm

Thank you! Works wonderfully. However, the cannon has 8 frames of rotation. Once it hits the last frame, it will not reset to frame 1. How do I do this so it can constantly cycle?
B
5
Posts: 37
Reputation: 299

Post » Sun Jul 19, 2015 8:37 pm

you can just make a condition:

on right pressed and animation frame is 8 set animation frame to 0
on left pressed and animation frame is 0 set animation frame to 8
B
52
S
22
G
12
Posts: 725
Reputation: 11,716

Post » Sun Jul 19, 2015 8:41 pm

or just use modulo
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816

Post » Sun Jul 19, 2015 8:59 pm

Anonnymitet wrote:you can just make a condition:

on right pressed and animation frame is 8 set animation frame to 0
on left pressed and animation frame is 0 set animation frame to 8


I'm doing this now, although it skips frame 0 when going right, and right to 7. (Frames being 0-7)

What would be the proper way to sequence this? Thank you for all your help so far, by the way.

Image
B
5
Posts: 37
Reputation: 299

Post » Sun Jul 19, 2015 9:01 pm

You can of course use modulo as madspy said :)

Here is a capx of the first example.
https://dl.dropboxusercontent.com/u/100 ... rames.capx

Usually the on pressed trigger fires so quick that it effects the next frame as well so it skips a frame. By adding a wait 0.05 sec before every action fixes that. I did not place the events in the example as sub events so I could comment it nicely. But you can use sub events.

But the most effective way would be to do as MadSpy suggested.
B
52
S
22
G
12
Posts: 725
Reputation: 11,716

Post » Sun Jul 19, 2015 9:15 pm

on right arrow pressed: sprite set animation frame to (self.animationframe+1)%self.animationframecount
on left arrow pressed: sprite set animation frame to (self.animationframe+self.animationframecount-1)%self.animationframecount
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816

Post » Sun Jul 19, 2015 9:34 pm

You guys are wonderful! Thank you so much. Working perfectly now.
B
5
Posts: 37
Reputation: 299

Post » Sun Jul 19, 2015 9:40 pm

Nice, did you try MadSpys solution? It's pretty good to learn about modulo so it would be a good practice :) Anyway, glad you got it to work! Good luck with your project! :D
B
52
S
22
G
12
Posts: 725
Reputation: 11,716

Next

Return to How do I....?

Who is online

Users browsing this forum: MadSpy and 3 guests