Legacy GM State machine sprites question

D

Dibidoolandas

Guest
Hey guys, I have a fairly complex question that I'll try and keep as simple as possible. Essentially I'm trying to rotate my sprite 45 degrees when it's going up/down a diagonal hill. I've found that using image_angle rotates the sprite AND the player's mask, which immediately causes clipping issues. It seems like draw_sprite_ext would be a better way to handle this, but here's where I run into problems.

My player's sprite code is handled almost entirely in a script run in the player's STEP event, not DRAW, so I can't actually run draw_sprite_ext. I'll show you the code setup, it was based on a tutorial by Shaun Spalding. My player uses a state machine, so the sprite code determines what state the player is in, and changes the sprite accordingly.

Code:
//Adjust sprite based on player state
switch (state)
{
    case states.normal:
    {
            image_speed = ispd;
            if (hsp == 0)
            {
                if !(key_right || key_left)
                {
                    sprite_index = psprites.stand;
                }
            else
            {
                sprite_index = psprites.walk;
                image_speed = (ispd/4) + abs(ispd * (hsp/4));
            }
            if (hdir != 0) image_xscale = hdir;
        break;
    }
    case states.trip:
    {
        sprite_index = psprites.trip;
    }
    break;
    case states.air_ride:
    {
        if (shoot == true) sprite_index = spr_player_r_s;
        else sprite_index = psprites.ride;
        image_xscale = 1;
    }
    break;
    case states.idle:
    {
        if (place_meeting(x,y+1,par_collide)) sprite_index = psprites.stand;
        if (!place_meeting(x,y+1,par_collide)) sprite_index = psprites.jump;
    }
    break;
This is just a small sample because I have a lot of states and there's some fairly complex stuff going on in there. Is there a reason I can't just migrate all of this to run from the draw event? I've tried and it doesn't even render my player's sprite (plus I assume this will all be unnecessary draw on processing power).

Any help would be appreciated. Ultimately I could just make a separate sprite that's rotated 45 degrees and -45 degrees, but I also have 22.5 degree hills that would need their own sprite, plus multiple behaviors within this angle, so it really seems inefficient to do it this way.
 

obscene

Member
Probably all you need to do...

1) Use a custom variable like draw_angle instead of image_angle and change that as needed. (It won't affect the mask).

2) Use draw_sprite_ext() in your draw event with draw_angle.
 
D

Dibidoolandas

Guest
Probably all you need to do...

1) Use a custom variable like draw_angle instead of image_angle and change that as needed. (It won't affect the mask).

2) Use draw_sprite_ext() in your draw event with draw_angle.
Thanks for replying.

So if I understand you correctly, I would actually keep all of my step code, but instead of changing the sprite there (or rotation or what have you), I would declare the variable there, which would be set in the draw event with draw_sprite_ext. So instead of, say, sprite_index = psprites.stand, I would instead create a variable like current_sprite = psprites.stand, and then in the draw_sprite_ext(current_sprite,etc.). And create variables for all those parameters, like rotation.

That makes sense to me, if I understand you correctly.
 
Top