Closed Manukineko closed 3 years ago
This is expected behaviour. Each itinerary moment is hidden behind an anonymous function so that the code will not execute ahead of time. In your code, from the second run on, there is 250ms worth of time where bgx
is still at its final value from the previous run, and 500ms worth of time where mgx
is doing the same. The offsets need to be set ahead of time, and care must also be taken to avoid having two itineraries active at the same time both trying to work on bgx
and mgx
.
Create:
sprite = 0;
animationDone = true;
mugshotSprite = [
[sprite_mugshot_BG1, spr_mugshot1],
[sprite_mugshot_BG2, spr_mugshot2],
];
bgx = -200;
mgx = -200;
Step:
if (keyboard_check_pressed(vk_left) && animationDone) {
sprite = (sprite+1) mod array_length(mugshotSprite);
animationDone = false;
bgx = -200;
mgx = -200;
Itinerary(0, [
[250, function() { Tween(InstanceVar("bgx"), 0, 500, ["type", te_cubic_out]); }],
[500, function() { Tween(InstanceVar("mgx"), 0, 500, ["type", te_cubic_out]); }],
[1000, function() { animationDone = true; }],
]);
}
I got it.
So the set
method doesn't pre-set the value when it is called in an Itinary, because Moment time is like a "delay".
I think it may be worth to update the documentation on that particular case.
By the way, I have a question :
actor
's methods ?It has nothing to do with the set
method in selectors. function() { ... }
is only a declaration, none of the code inside runs until it actually gets called, which in the case of itinerary actors is when the moment time is reached. It is the same reason why code in script functions should not be expected to run unless it is being called.
By the same logic, the solution to your question is to hide those actions behind an anonymous function:
Create:
animateBgxMgx = function() {
animationDone = false;
bgx = -200;
mgx = -200;
Itinerary(0, [
[250, function() { Tween(InstanceVar("bgx"), 0, 500, ["type", te_cubic_out]); }],
[500, function() { Tween(InstanceVar("mgx"), 0, 500, ["type", te_cubic_out]); }],
[1000, function() { animationDone = true; }],
]);
};
Then call it like animateBgxMgx();
or Delay(500, animateBgxMgx);
later.
Create Event
step event
Draw event
When Left is pressed, the next sprite is first set to the actual value of bgx and mgx, and will be set to the value define in the
set
method only when the timer in the ItinaryActor will reach the given time of each action. For short :Actually, I'm not sure if it's a bug or if it works just as intended.