Windows Animating Sprites with movement controls [SOLVED]

W

Wintermute()

Guest
HI GMS'ers,

I'm struggling to figure out how to animate a 12 frame 2D spaceship I have a model of. It's for use in a top down shooter I've been making. I've been slowly upgrading all the models in my game to fully animated modeled sprites for all the enemies and scenery, but now my main player sprite I have been using sticks out like a sore thumb, flat and lifeless, by comparison.

So i've got a nice 12 frame sprite of a spaceship to use, all gifs, which basically covers the ship tilting it's wings left and right to simulate turning. What i'm stuck with is how to control the animation for it with user movement controls. Up until now I've simply used sprite index to change my enemy and scenery sprites based on game conditions (hit, boosts, explosions, etc) and reset them or destroy them. but now i need to so something very different, ie:

action: Player presses move left
gms: change sprite for player ship so it displays the animation that tilts the ship down to the left
action: PLayer releases move left button
gms: change sprite for player ship so it displays the animation that reverses the previous movement, back to the center (default) sprite.

The tricky thing there that gets me is how to make it so when press left is released, the next animation starts ffrom where the previous one left off - so you get a smooth animation. I hope I explained that clearly enough ?

If anyone has an explanation on how to do this, i'd really appreciate it, thank you !
 
V

Vincent

Guest
I don't know if this will apply to you, but in my game I use this cod to make the animation be more or less smooth
Code:
if keyboard_check (vk_nokey)
    {
    image_speed = 0
    }
This will make your sprite to be frozen where it was. I don't know if you were looking for this, but I hope it works!
 

matharoo

manualman
GameMaker Dev.
Example:
Code:
if (left_pressed){
    sprite_index = spr_left;
    if (image_index < 10) image_speed = 1; else image_speed = 0;
}
else if (sprite_index!=spr_normal){
    if (image_index > 0) image_speed = -1;
    else sprite_index = spr_normal;
}
This is just to give an idea. What you want to do is, when the player releases the button, make the image_speed negative so that it would travel back to the normal state from the frame it is currently at.
 
W

Wintermute()

Guest
Example:
Code:
if (left_pressed){
    sprite_index = spr_left;
    if (image_index < 10) image_speed = 1; else image_speed = 0;
}
else if (sprite_index!=spr_normal){
    if (image_index > 0) image_speed = -1;
    else sprite_index = spr_normal;
}
This is just to give an idea. What you want to do is, when the player releases the button, make the image_speed negative so that it would travel back to the normal state from the frame it is currently at.
a-HA ! negative image speed. thank you so much for that code example too.

so i would have the key release event as this line of code ?

Code:
else if (sprite_index!=spr_normal){
    if (image_index > 0) image_speed = -1;
    else sprite_index = spr_normal;
}
 

matharoo

manualman
GameMaker Dev.
a-HA ! negative image speed. thank you so much for that code example too.

so i would have the key release event as this line of code ?

Code:
else if (sprite_index!=spr_normal){
    if (image_index > 0) image_speed = -1;
    else sprite_index = spr_normal;
}
I coded that with the Step event in mind. So I suggest you code it in the Step event. Do not exactly copy-paste my code; that would not work. It's just an example to explain the concept.
 
W

Wintermute()

Guest
I coded that with the Step event in mind. So I suggest you code it in the Step event. Do not exactly copy-paste my code; that would not work. It's just an example to explain the concept.
Thanks - no, I wasn't going to copy paste :) I do take the ideas you have laid out in the example.

What I was referring to for the key release event that runs the sprite back to default in reverese, was just attempting to confirm that it would be where you have the code to check

[if the Sprite index is not at default, and if the sub-image is in the left hand turn range of subimages, then set the image speed to negative, otherwise set it to default]
 
W

Wintermute()

Guest
just to close this one....this is how I got it to work for the 5 frame animation of my ship turning left, then on release left, reverse the animation of the ship to normal state, unless ship is held at full turn then lock frame until released:

on left press:


Code:
image_angle = image_angle + 2.6;
sprite_index = spr_player_3d_left;
if (image_index < 5)
{
image_speed = 1/4;
}
if image_index=4
{
image_speed = 0;
}
release left press:


Code:
if (sprite_index=!spr_player_3d_center)
{
if (image_index >0)
image_speed = -1/4;
}
else sprite_index=spr_player_3d_center;
Thank you @matharoo for your help :)
 
Top