• 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 Change of sprite/animation when pushing moveable block (SOLVED)

F

FamicomLink

Guest
Hey there, first post.
I've been working on a simple platformer for a few months and I've come to a slight slow down with some coding issues for sprite/animation changes for a specific situation. I have looked all over and haven't found any proper solutions for this problem either, so I was hoping anyone here could help out.

I have a pushable block object made, but I can't get the sprites to change when pushing the block on the left or right side, and they only do change (sometimes) when the block is against a wall- and in one specific area while walking aboveby the block.
This here is the code used in the player object's step event under the platform physics action I have set up.
What exactly am I doing wrong?

Code:
if keyboard_check(vk_left) && (place_meeting(y,x-2, obj_block_push))  {sprite_index=spr_player_mask; sprite_index = spr_player_walk}
if keyboard_check(vk_right) && (place_meeting(y,x+2, obj_block_push))  {sprite_index=spr_player_mask; sprite_index = spr_player_walk}
 

Paskaler

Member
Post the entire step event, because all seems well here, except that you don't need to assign the sprite index twice. In the create event or the object properties on the left set the mask index(mask_index in code) to spr_player_mask.
 
F

FamicomLink

Guest
Post the entire step event, because all seems well here, except that you don't need to assign the sprite index twice. In the create event or the object properties on the left set the mask index(mask_index in code) to spr_player_mask.
Alright but it's pretty long.

Code:
/// Platform Physics
var rkey = keyboard_check(vk_right);
var lkey = keyboard_check(vk_left);
var jkey = keyboard_check(ord("X"));
var jkeyp = keyboard_check_pressed(ord("X"));
var runkey = keyboard_check(ord("Z"));
var resetkey = keyboard_check(vk_tab);
var upkey = keyboard_check(vk_up);
var downkey  = keyboard_check(vk_down);
var keyattack = keyboard_check_pressed(ord("C"));

// Check for ground
if (place_meeting(x, y+1, obj_wall)){
    vspd = 0;
  
    // Jumping
    if (jkeyp)              {
    audio_play_sound(snd_jump,1,0)
    if (jkey) vspd = -jspd;
    draw_yscale = 1.5;
    draw_xscale = .75
    }
} else {
    // Gravity
    if (vspd < 10)
        vspd += grav;
    }
  
    if (keyboard_check_released(ord("X")) && vspd <-4) {
        vspd = -4;
    }

if crouch == 0{ //make sure you're not crouching
    //Run
    if (runkey)  {
    
        spd = rspd;
      
    }else{
        spd = wspd;
    }
  
    // Moving Right
    if (rkey) {
        if (hspd < spd) {
            hspd += fric;
        } else {
            hspd = spd;
        }
    }
    // Moving Left
    if (lkey) {
        if (hspd > -spd) {
            hspd -= fric;
        } else {
            hspd = -spd;
        }
    }
    // Check for not moving
    if ((!rkey && !lkey) || (rkey && lkey)) {
        if (hspd != 0) {
            if (hspd < 0) {
                hspd += fric;
            } else {
                hspd -= fric;
            }
        }
    }
}
else{
    spd = 0;
    hspd = 0;
}
// Horizontal Collisions
if (place_meeting(x+hspd, y, obj_wall)) {
    while (!place_meeting(x+sign(hspd), y, obj_wall)) {
        x+= sign(hspd);
    }
    hspd = 0;
}
//Move Horizontally
x += hspd;
// Vertical Collisions
if (place_meeting(x, y+vspd, obj_wall)) {
    while (!place_meeting(x, y+sign(vspd), obj_wall)) {
        y += sign (vspd);
    }
    vspd = 0;
}
//Move Vertically
y += vspd;

//Control Sprites
if (yprevious != y) {
    sprite_index = spr_player_jump;
    image_speed = .25;
    image_index = y>yprevious
} else {
    if (xprevious != x) {
        sprite_index = spr_player_walk2;
        image_speed = .25;
} else {
        sprite_index = spr_player_stand
        image_speed = .20;
    }
}

// Control Direction player is facing
if (xprevious < x) {
    image_xscale = 1;
} else if (xprevious > x) {
    image_xscale = -1;
}

//Player Headbump
if (place_meeting(x, y-1, obj_wall))  {sprite_index=spr_player_bump}

//Crouch
if place_meeting(x,y+1,obj_wall){crouch = downkey;}
if crouch == 0 {mask_index = spr_player_mask;}
if crouch == 1 {mask_index = spr_player_mask_crouch; sprite_index = spr_player_crouch;}

//Pushing
if keyboard_check(vk_left) && (place_meeting(y,x-2, obj_block_push))  {sprite_index=spr_player_mask; sprite_index = spr_player_walk}
if keyboard_check(vk_right) && (place_meeting(y,x+2, obj_block_push))  {sprite_index=spr_player_mask; sprite_index = spr_player_walk}
[code/]
 
G

Gillen82

Guest
Your x and y arguments are in the wrong order. Would this be causing an issue?

Code:
//Pushing
if keyboard_check(vk_left) && (place_meeting(y,x-2, obj_block_push))  {sprite_index=spr_player_mask; sprite_index = spr_player_walk}
if keyboard_check(vk_right) && (place_meeting(y,x+2, obj_block_push))  {sprite_index=spr_player_mask; sprite_index = spr_player_walk}
[code/]
 
F

FamicomLink

Guest
Your x and y arguments are in the wrong order. Would this be causing an issue?
Well I feel relatively stupid right now, but everyone makes mistakes and learns from them.
switching the arguments worked, thanks a bunch!
 
Top