[REQUEST] Sine action "RESET"

Discussion and feedback on Construct 2

Post » Mon Mar 11, 2013 9:48 pm

Hello C2 development team,

I'd like to point out a missing feature of the Sine Behavior:

I'm missing the Sine Reset action. Once the Sine is activated it oscillates back and fort to the eternity. If set to inactive and back to active, it starts exactly from its last value, which is not always wanted.

For example, if I would like to perform just a quarter period movement (progress 0 to 1), I'm using a condition to stop, i.e. inactivate the Sine behavior. Later, I'd like to repeat on the same object that quarter period movement from the beginning (progress 0 to 1 again), and not as noted from the last progress point (1 through 0 to -1). For now it appears to be impossible...?!
B
11
S
3
G
3
Posts: 79
Reputation: 3,343

Post » Tue Mar 12, 2013 2:41 am

+1
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Post » Wed Mar 13, 2013 2:25 am

+2
B
20
S
5
G
8
Posts: 325
Reputation: 6,473

Post » Wed Mar 13, 2013 3:53 pm

+3
Luca ConTato [RisingPixel]
Image
B
21
S
7
G
1
Posts: 102
Reputation: 2,680

Post » Thu Mar 14, 2013 2:22 pm

Hi again, I've taken a look at the Sine Behavior code. If I'm not wrong, it should be enough to add following code to add a Reset action:

edittime.js
AddAction(5, af_none, "Reset", "", "{my} <b>Reset</b>", "Reset the wave function.", "ResetWave");

runtime.js
Acts.prototype.ResetWave = function (){this.i = 0;};

I've tested it. It works as expected. On Reset, the Sine function starts at 0. Maybe you could test it too, and it could be added to the next C2 issue??
B
11
S
3
G
3
Posts: 79
Reputation: 3,343

Post » Sun Mar 17, 2013 8:29 pm

I've just experimented with that Sine Reset function and noticed, that the period offset and period random offset were not considered. So here is an extended code (actually a copy-paste from the Sine initializing function), which considers those two:

runtime.js
Acts.prototype.ResetWave = function ()
{ if (this.period === 0) this.i = 0;
   else { // if some period offset is given, it should reset to that offset
     this.i = (this.properties[5] / this.period) * _2pi;
     this.i += ((Math.random() * this.properties[6]) / this.period) * _2pi;
   }
};

I've compiled an example with the extended Sine behavior, which can be seen here. The reset here demonstrates repeatable 0.25 to 0.75 sine cycle, instead of continually going back and fort.
(Of course in that particular case, there could be a workaround with an ABS() function for the falling (minus) sine function):

EXAMPLE / CAPXXManBG2013-03-17 20:50:37
B
11
S
3
G
3
Posts: 79
Reputation: 3,343

Post » Fri May 03, 2013 12:49 pm

This is just what I needed, thanks a lot!
B
8
S
2
Posts: 23
Reputation: 692

Post » Fri May 03, 2013 4:26 pm

remember to never update your OOTB behaviors and plugins. Always make a new one like CustomSine or MySine.
B
30
S
10
G
7
Posts: 416
Reputation: 7,239

Post » Fri May 03, 2013 4:56 pm

Not sure if I'm being dumb, but is it also possible to decide which direction the sine starts with? I'm using it to have alien ships fly in a bit of a pattern, but sometimes I want them to start off moving left rather than right. Always seems to start in the same direction.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Fri May 03, 2013 5:07 pm

@farflamex
When you place some sprites down with Sine behaviour, you can change each ones "Period offset", which is how far it is through it's cycle I think. As with the topic itself, it's currently not possible to change where it is in it's movement, which hopefully will get officially implemented :P
Hope this helps!
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Avengium, DonpatchXD, eli0s, MadSpy and 13 guests