How do I "ping pong" between 2 numbers without randomization

Get help using Construct 2

Post » Wed Apr 16, 2014 12:49 pm

newt wrote:Shake is one of the simplest things you can do.
Just do it your self using variables, the random() expression, and the system scrollx, and scrolly.
Like:
+> global variable "shake"= 1
-->system scroll x to scrollx+random(-30,30)
-->system scroll y to scrolly+random(-30,30)


This worked.
But I would want to have a stable shake (without random):
(I want scrolly first to add VarNum1 pixels and then subsctract VarNum2 pixels)

I tried:
if shake = 1 --> system scroll y to scrolly+5
--> set shake to 2
if shake = 2 --> system scroll y to scrolly-5
--> set shake to 1

I expected the screen to go go up and down, moving 10 pixels (shake effect). But nothing happened.
B
25
S
6
G
7
Posts: 676
Reputation: 5,562

Post » Wed Apr 16, 2014 2:16 pm

By reading that it seems the program is reading it like this: shake = 1 so set shake to 2, now shake = 2 so set shake to 1. Thus it will just stay as shake = 1.
Try using an else, incorporated into the second event, that should ensure it doesn't do both events.

Example capx:
ManualScreenShake.capx
You do not have the required permissions to view the files attached to this post.
B
42
S
14
G
3
Posts: 165
Reputation: 5,115

Post » Wed Apr 16, 2014 2:46 pm

Thanks, @Sumyjkl
B
25
S
6
G
7
Posts: 676
Reputation: 5,562

Post » Wed Apr 16, 2014 2:50 pm

You can use this: system scroll x to scrollx+choose(-30,30)
B
28
S
2
G
3
Posts: 20
Reputation: 3,535

Post » Wed Apr 16, 2014 3:17 pm

@jastrazz I tried, but action "choose" also uses random.
So it chooses sometimes 1 of the values more than once in a row.
@Sumyjkl solved it for me.
B
25
S
6
G
7
Posts: 676
Reputation: 5,562

Post » Wed Apr 16, 2014 3:39 pm

You could try the built in shake. Just add the "Scroll to" behavior and then call its shake action.
B
53
S
16
G
6
Posts: 718
Reputation: 9,150


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest