sine effect

Get help using Construct 2

Post » Tue Mar 04, 2014 10:20 pm

Using the sine effect, is there a way to have the horizontal movement go forward a certain amount and the go back?
In other words, without any special commands, the sine effect moves my sprite back and forth horizontally. Unfortunatley, in moves it back and forth the same distance forward and backward.
Can I set sine so that it moves forward a certain amount and moves backwards a different amount?

What I'm getting at is that I want a sprite to "peek" out behind another sprite. It moves forward and "peeks" out fine but then it sways in the other direction "peeking" out the other side.
I just want it to "peek" out in the forward direction and then move back behind the other sprite.
B
7
S
2
Posts: 158
Reputation: 1,021

Post » Tue Mar 04, 2014 10:27 pm

You could use the sprite's current position to calculate when it's at the peak or trough of the sine wave, and change the sine behavior's amplitude at that time.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Tue Mar 04, 2014 10:38 pm

Or you can make the peaking sprite invisible when it's going too far? Or just adjust the normal position of the moving sprite? there are quite many ways to make this happen. It'll depend on what the situation is.
Need help? Upload .capx file with your question.
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

Post » Tue Mar 04, 2014 10:57 pm

the problem is spriteA is only as big as too hide the main sprite so that the sine effect peeks out the front and the back. I was hoping I could put some kind of restriction on the sine effect to prevent it from showing on the other side of the main sprite.
Making it invisible alters the effect I was going for. I want to have the main sprite slide out from behind another sprite.
I'm sure there are many ways to get this effect but I was just trying with the sine effect. I basically just wanted the main sprite to peek out a ways and then go back to it's position hidden behind spriteA
Maybe sine is not the best option
B
7
S
2
Posts: 158
Reputation: 1,021

Post » Wed Mar 05, 2014 12:45 am

The point is, you can just query the sine behavior to find out when you are behind the sprite, then change the sine behavior to not come out the other side.

For example, let's say both sprites start at the same spot. Start the sine behavior, sprite peaks out, comes back, but before it has a chance to peak out the other side, you alter the parameters of the sine behavior to prevent that.

More specifically, you can use the CyclePosition expression to know when you are mid-way through the cycle (this is the point after you've peaked out and come back), and when that happens do things like enable and disable the sine behavior (this may re-start it I'm not sure), change the magnitude to 0, or manually re-set the sprite position to the correct place every frame until CyclePosition is again on the 'peaking' side of the sine wave.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Wed Mar 05, 2014 1:36 am

Thanks for the reply. I'll have to try that and see how it works out.
I did come up with a different solution tho I'm not too crazy about it.
after the sine movement in the front, I set a time to turn on opacity.
It seems to be enough time to peek the sprite in the front and then right before coming out the back, it disappears.
B
7
S
2
Posts: 158
Reputation: 1,021


Return to How do I....?

Who is online

Users browsing this forum: koops and 7 guests