• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Gamepad Idle issues

mar_cuz

Member
Hi Guys,


I'm having issues with using the gamepad anologue joystick with my player in my isometric game. The player moves fine, I've locked the directions to 8 and the sprite changes to the correct one with each direction. the problem is when the player stops, I need it to change to the idle sprite which I set by: if sprite_index = left idle_sprite = idleft. so when the player stops, it should change to the idle sprite. I think there is an issue with the left analogue stick because it only idles with the right idle sprite. I'm also using a move state and an idle state. please see my code:

//Create Event
Code:
pad_num = 0;

h = 0;
v = 0;

runspeed = 0;
runspeed_max = 4;
runspeed_min = 0;
depth = -y;

image_speed = 0.6;

idle_sprite = right;

IDLE = 10;
MOVE = 11;

state = IDLE;
//Step Event
Code:
depth = -y;
camera_movement();

gamepad_set_axis_deadzone(pad_num, 0.5);
h_point = gamepad_axis_value(pad_num, gp_axislh);
v_point = gamepad_axis_value(pad_num, gp_axislv);   

pdir = point_direction(0, 0, h_point, v_point);

if runspeed > runspeed_max {
    runspeed = runspeed_max;
    }
    
if runspeed < runspeed_min {
    runspeed = runspeed_min;
    }

switch (state) {
    
    case IDLE:
        {
        var h_move = gamepad_axis_value(pad_num, gp_axislh);
        var v_move = gamepad_axis_value(pad_num, gp_axislv);
        pdir = point_direction(0, 0, h_move, v_move);
        sprite_index = idle_sprite;
        runspeed = runspeed_min;
        if ((h_move != 0) || (v_move != 0)) {
            state = MOVE;
            }
        }
    break;
    case MOVE:
        {   
        
        
//move variables
var h_move = gamepad_axis_value(pad_num, gp_axislh);
var v_move = gamepad_axis_value(pad_num, gp_axislv);
pdir = point_direction(0, 0, h_move, v_move);

//Set Walking Sprites
if  pdir <20  {
    pdir = 0;
    sprite_index = right;
    }

if pdir > 20 && pdir <90 {
    pdir = 45;
    sprite_index = upright1;
    }
    
if pdir >45 && pdir <140 {
   pdir = 90;
    sprite_index = up;
    }
    
if pdir >90 && pdir <180 {
    pdir = 140;
    sprite_index = upleft;
    }
    
if pdir >140 && pdir <225 {
    pdir = 180;
    sprite_index = left;
    }
    
if pdir >180 && pdir <270 {
    pdir = 225;
    sprite_index =downleft;
}
    
if pdir >225 && pdir <315 {
    pdir = 270;
    sprite_index = down;
    idle_sprite = down;
    }
    
if pdir >270 && pdir <360 {
    pdir = 315;
    sprite_index = downright;
    }
    
//Player Movement
if ((h_move != 0) || (v_move != 0))
{

var checkX = lengthdir_x(runspeed,pdir);
var checkY = lengthdir_y(runspeed,pdir);

if !place_meeting(x+checkX,y+checkY,oParSolid) {
    runspeed += 0.2;
    x+= checkX;
    y+= checkY;
    }

}


if ((h_move = 0) && (v_move = 0)) {
    state = IDLE;
           }
    }
    break;
}

//Set Idle Sprite
if sprite_index = right  {
    idle_sprite = idright;
    }

    
if sprite_index = upright1 {
    idle_sprite = idrightup;
    }

if sprite_index = up {
    idle_sprite = idup;
    }
    
if sprite_index = upleft {
    idle_sprite = idleftup;
    }   
    
if sprite_index = left {
    idle_sprite = idleft;
    }
    
if sprite_index = downleft {
    idle_sprite = idleftdown;
    }
    
if sprite_index = down {
    idle_sprite = iddown;
    }
    
if sprite_index = downright {
    idle_sprite = idrightdown;
    }
please help and please ignore my messy code :)
 
Top