I create a simple platformer project following a tutorial on Youtube. Everything is working fine, except for one little problem that is driving me nuts. When the sprite of my character collide with a oWall object (the one I use as ground and walls), the right one is fine, but the left one is off by one pixel. A gif may exemplify what I'm trying to say better:
Here is all the code of the game (<100 lines of code):
Create Event of oHero:myGravity= 1;
mySpeed= 4;
speedJump= 12;
speedH = 0;
speedV= 0;
Step Event of oHero (PHYSICS):KEY_LEFT = keyboard_check(vk_left) or keyboard_check(ord('A'));
KEY_RIGHT = keyboard_check(vk_right) or keyboard_check(ord('D'));
KEY_DOWN = keyboard_check(vk_down) or keyboard_check(ord('S'));
KEY_JUMP = keyboard_check(vk_up) or keyboard_check(ord('W'));
if (place_meeting(x, y + 1, oWall))
{
speedV = 0;
if (KEY_JUMP) speedV = -speedJump;
}
else
{
if (speedV < 10) speedV += myGravity;
}
if (KEY_RIGHT) speedH = mySpeed;
if (KEY_LEFT) speedH = -mySpeed;
if ((!KEY_LEFT and !KEY_RIGHT) or (KEY_LEFT and KEY_RIGHT)) speedH = 0;
// HORIZONTAL
if (place_meeting(x + speedH , y, oWall))
{
while(!place_meeting(x + sign(speedH), y, oWall))
{
x += sign(speedH);
}
speedH = 0;
}
x += speedH;
// VERTICAL
if (place_meeting(x, y + speedV, oWall))
{
while(!place_meeting(x, y + sign(speedV), oWall))
{
y += sign(speedV);
}
speedV = 0;
}
y += speedV;
Step Event of oHero (SPRITES):if (yprevious != y)
{
sprite_index = sHeroJumping;
mask_index = sHeroJumpingMask;
image_speed = 0;
image_index = (y > yprevious);
}
else
{
if (xprevious != x)
{
sprite_index = sHeroWalking;
mask_index = sHeroWalkingMask;
image_speed = 0.3;
}
else
{
if (KEY_DOWN)
{
sprite_index = sHeroDown;
mask_index = sHeroDownMask;
}
else
{
sprite_index = sHeroIdle;
mask_index = sHeroIdleMask;
}
}
}
if (speedH != 0) image_xscale = sign(speedH);
The oHero sprite mask and all the animations mask are centered and have the same width. I'm not using anything solid neither the build-in gravity stuff of Game Maker. Every sprite have Precise Collision Checking on.
I know it have something to do with image_xscale because everything works fine if I don't flip the sprite. I'm using Game Maker Studio (v1.4).
So... is image_xscale messing with the collision box? anything wrong in the code? any workaround for this problem?