[SOLVED] Sprite gets thinner or thicker when i change image_xscale

C

C4llThSamu

Guest
I wanted to flip my character when he moved to the sides,so i used the following code :

if (hsp != 0) image_xscale = sign(hsp);

Its working well,but the problem is : The sprite gets thinner when image_xscale is negative,and thicker when is positive,how do i fix this? (Stupid question,probably...)

Normal Sprite / Thinner Sprite

 

Attachments

C

C4llThSamu

Guest
My guess is other code interfering. Post the entire event, and anything else you feel may be relevant.
The entire "Step" event (but the error is most likely to be at the "Animation" part)

//Get Player Input
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);

//Calcule Movement
var move = key_right - key_left

hsp = move * walksp;

vsp = vsp + grv;

// Jump

if (place_meeting(x,y+1,SolidOBJ)) and (key_jump) {
vsp = -7;
}

//Horizontal Collision
if (place_meeting(x+hsp,y,SolidOBJ))
{
while (!place_meeting(x+sign(hsp),y,SolidOBJ))
{
x = x + sign(hsp);
}
hsp = 0;
}

x = x + hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,SolidOBJ))
{
while (!place_meeting(x,y+sign(vsp),SolidOBJ)) {
y = y + sign(vsp);
}
vsp = 0
}

y = y + vsp;

//Animation

if (!place_meeting(x,y+1,SolidOBJ))
{
sprite_index = jPlayer;
image_speed = 0;
if (sign(vsp) > 0) image_index = 1 ; else image_index = 0;
}
else
{
image_speed = 1;
if hsp = 0
{
sprite_index = sPlayer;
}
else
{
sprite_index = wPlayer;
image_speed = 7;
}
}
if (hsp != 0) image_xscale = sign(hsp);
 

Paskaler

Member
Select image_xscale in the code editor or use Shift+Ctrl+F and input in the search window image_xscale. This will show you where you used image_xscale in the entire project. Maybe you modified it somewhere else but forgot.
 
C

C4llThSamu

Guest
Select image_xscale in the code editor or use Shift+Ctrl+F and input in the search window image_xscale. This will show you where you used image_xscale in the entire project. Maybe you modified it somewhere else but forgot.
Already checked all the events in the character object,and the image_xscale wasn't modified before :/ (There are only 2 events in the project,a create,and a step one,so there isn't much code...)
 
G

GSKV

Guest
You might have changed the size of your sprite so it's origin point and it's collision box automatically changed their positions. You should re-check that
 
C

C4llThSamu

Guest
You might have changed the size of your sprite so it's origin point and it's collision box automatically changed their positions. You should re-check that
I did some changes at the code and origin point,its now working properly,thx guys.
 
F

Flapkac Beater

Guest
PLEASE SHARE WITH US WHAT YOU DID TO FIX THE PROBLEM!
I'M SUFFERING FROM THE SAME THING. PLEASE HELP
 
J

Jacob N Zamora

Guest
I did this.


if (sign(hsp) > 0) image_xscale = 4; else image_xscale = -4;

Instead of :
if (hsp != 0) image_xscale = sign(hsp);

Because as I moved the player when testing it would shrink.
 

TheouAegis

Member
Yeah because all you did was take the default orientation and not scale it. You simply flipped it. In your first code, you are setting the scale to 4, but in the code that you claim didn't work, you were setting the scale to 1. The code works, you just had no idea what it was actually doing.

Also, the first code will set the scale to -4 when not moving, whereas the second code will not even touch the scale when it's not moving. So yeah, that may or may not be what you actually want.
 
J

Jacob N Zamora

Guest
Yeah because all you did was take the default orientation and not scale it. You simply flipped it. In your first code, you are setting the scale to 4, but in the code that you claim didn't work, you were setting the scale to 1. The code works, you just had no idea what it was actually doing.

Also, the first code will set the scale to -4 when not moving, whereas the second code will not even touch the scale when it's not moving. So yeah, that may or may not be what you actually want.
it is what I want I also fixed the scale from -4 when not moving. Thank you though.
 
Top