#Changing image_index to a certain amount of animation frames

5 messages · Page 1 of 1 (latest)

nimble hornet
#

Hello. I wouldn't call this any urgent problem, but I wrote some (simple) code to change the image_index to an animated sprite when you press 'W' or 'S' (corresponding to going up or down) on the keyboard as a transitional animation that changes back to the normal image_index of the object when you're going left or right, or not moving. I'm currently having a hard time even initializing the sprite change in the first place though, and when I got the debug info for direction hoping direction would do the trick instead of checking for keys, it returned 0 even though I believe the angles were, in theory, 270 and 90 degrees.

Another question I had before I show the code for this (as well as the object (player's) movement code), is if its possible to only play a certain range of frames from an animated sprite to play in succession and then have it stop on a certain frame if a certain action happens (in this case, I want to check if a button is pressed down for long enough to freeze at that frame, and then when the key is released for it to play an additional few frames before going back to its normal image_index). I tried looking through the manual for anything that could help me achieve this after I get through the first problem, but I was kind of lost.

Anyways, this is the code in my player (o_ship)'s step event that covers movement and the effect im trying to achieve.

`
#region key inputs

var keyleft = (keyboard_check(ord ("A")));
var keyright = (keyboard_check(ord ("D")));
var keyup = (keyboard_check(ord ("W")));
var keydown = (keyboard_check(ord ("S")));

//basic movement calculation

var deltax = (keyright - keyleft);
var deltay = (keydown - keyup);

x += spd * deltax;
y += spd * deltay;

#endregion

#region transitional animation

if (keyup || keydown)
{
image_index = s_ship_turn;
}
else
{
image_index = s_ship;
}

#region`

Suggestions are appreciated, and I hope this post is not too wordy. I can elaborate further if the way I describe what I'm trying to do is too confusing.

gleaming seal
warm wedgeBOT
#

This variable returns the current sprite set for the instance, or -1 if the instance has no sprite associated with it.

gleaming seal
#

so:

sprite_index = s_ship;

as an example