Drag And Drop Scripted actions doesn't play cause the variable counter doesn't have interger number

Z

Ziliock

Guest
Sorry for my bad english
I just need that, I have an event who checks the frames of an animation, but if I play the animation in a different speed, like 0.3 some of the checks will not activate, because instead being in the frame 3, it would be the frame 3.5
How do I fix that?
 
Sorry for my bad english
I just need that, I have an event who checks the frames of an animation, but if I play the animation in a different speed, like 0.3 some of the checks will not activate, because instead being in the frame 3, it would be the frame 3.5
How do I fix that?
Yeah these checks are always annoying. I don't know the ideal method for doing this but you could try this for now.

if abs(3-frame) < frame_speed/2 {
Your code
}

Frame is just your frame variable, it can be a decimal like you said. Frame speed is just the speed in which the frame is changing, in your case you said 0.3. I think this should work unless I messed it up.
 

TheouAegis

Member
What version of GM are you using? Prior to Studio 2, you could check in the srep event:

if image_index + image_speed >= frame

That would make it trigger the moment itrolls into the next frame.

FYI values of 1, 1/2, 1/4, 1/8, 1/16, and 1/32 will land on every frame's initial moment. Speeds in between, such as 1/3, 1/5, 1/6, 1/7, 1/9, and 1/10 will miss most frames' initial moments. And naturally, multiples of the values will miss some frames' initial moments. (Oddly, frame 1 rarely gets missed.)
 

CMAllen

Member
If you want to check for the *exact* step where a sprite's image swaps between one frame and the next, use the floor() function to drop the decimal values. However, using a floor comparison check in this manner will return true for the remainder of that frame, so you need a second 'checked' variable to pass over this test for subsequent step evaluations until the next frame. Ex:
Code:
if (floor(image_index) == 3) && (checked == false))
{
      //do the actions
     checked = true;
}
else if(floor(image_index) != 3 && (checked == true))
{
     checked == false;
}
This code will evaluate true only on the first step that image_index is 3 or greater.
 
Top