• 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!

Ground displaced while changing masks

T

Toxicosis

Guest
I've gotten a really weird bug this time around.

I wanted the player to crouch, but now when I hit down the crouch button in midair, the player stops falling. They resume falling if they move, or if the crouching button is released. It always starts at the same height too, which is disconcerting. I'm not sure what's going on. It starts 192 px above ground, every time, like clockwork, and I can jump from that height too, which means that for some reason, it's getting signaled that it's hit the ground.

I've managed to narrow the bug down to a mask swapping operation (used so the player can reduce their profile while crouching). I don't have the slightest clue of what's going on, help plz ;(

What I've been able to determine is...
It always starts 192 pixels above ground. That's twice the sprite height, but altering the sprite height doesn't seem to change anything.

Anyone ever had a problem like this?
 
T

Toxicosis

Guest
/*We can't just pick an object anymore. We've got to switch up the sprites.*/
var frame_wanted, index_wanted = 0;
delta_x_draw = 0;


if keyboard_check(vk_down) crouching = 1;
else crouching = 0;


//Set frame and mask.
if crouching == 1
{
mask_index = spr_index_player_crouch;
frame_wanted = spr_index_player;
index_wanted = 6;
if player_dir != 0
{
index_wanted = 9;
index_wanted += frame_count div 5;
frame_count++;
if frame_count == 10
frame_count = 0;
break;
}
}
else
{
{
mask_index = spr_index_player;
frame_wanted = spr_index_player;
if player_dir == 0 index_wanted = 0;
if player_dir != 0
{
index_wanted = 1;
if frame_count == 9 frame_count = 0;
index_wanted += frame_count div 3;
frame_count++;
}
if punch > 0 && punch < 8
{
if attack_mode = 1
index_wanted = 5;
else index_wanted = 7;
delta_x_draw = 64*facing;
}
break;
}
}
}

var store_index;
store_index = mask_index;

//It makes sure there's room enough to un-crouch before the player crouches.
mask_index = frame_wanted; //Select the kind of room to check for.

if place_meeting(x,y,obj_wallz) //Check if there's room for it.
{
mask_index = store_index; //If not, reset the mask.
}
image_index = index_wanted; //Finally, set the player to the subimage they sought.
 

FrostyCat

Redemption Seeker
Make sure the crouching mask's origin accounts for the height missing from the standing mask. For example, if your standing mask's origin is at (0, 0) and the crouching mask is 64 pixels shorter, the crouching mask's origin needs to be at (0, -64) to retain the consistency.

Edit: Corrected coordinates.
 
T

Toxicosis

Guest
I'm afraid that only made it worse.

Now instead of having one "extra level" at 192 px, I have two, with an additional one at 12 px above ground. Coincidentally, that's the displacement of the crouching mask's origin.

EDIT: I removed the more confusing part of my code, set the mask exactly once at the start, and it works. I'll just be scrapping the code and making a more readable one now. The moral is, I should not try to be too clever by half. I'm not. XP
 
Last edited by a moderator:
Top