Sprite distortion issue need help

DTheChemist

Member
Ok heres my first error code issue after following a Yoyo games youtube video tutorial.

GML:
/// @desc Core Player Logic

//Get Player Inputs

key_left= keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
//key_down = keyboard_check(vk_down);
key_jump = keyboard_check_pressed(vk_space);

//Calculate movement
var _move = key_right - key_left;

hsp = _move * walksp;
//x = x + hsp;
vsp = vsp + grv;//vertical speed
//x = x + hsp;
//y = y + vsp;

if (place_meeting(x,y+1,oWall)) && (key_jump)
{
    vsp = -jumpsp
}

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

}
x = x + hsp;

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

}
y = y + vsp;

//Animation
if (!place_meeting(x,y+1,oWall))
{
    sprite_index = jPlayer;
    image_speed = 0;
    if (vsp > 0) image_index = 1; else image_index = 0;///the frames of jump
   
}
else
{
    image_speed = 1;
    if (hsp == 0)
    {
        sprite_index = sPlayer;///the idle animation sprites
    }
    else
    {
        sprite_index = wPlayer;///the walk animation sprites
    }
}

if (hsp != 0) image_xscale = sign(hsp);///flips sprite left or right

my character becomes distorted in scale when i start to walk or shakes in animation error when i land from a jump. whats wrong with the code? Im still fresh at this engine

short video example here

 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
Are you setting image_xscale anywhere else? Output its value via show_debug_message to get a better idea about what's happening. For example, if you're using low-resolution graphics and scaling them up in code, you'll have to keep this in mind and keep it scaled accordingly when assigning values to it.
 

DTheChemist

Member
Im not entire sure what you mean but do you mean maybe on the actual sprite import maybe? its odd because before i added more code it wasnt doing that at all. when i started adding the actual expressions watching the video tutorial to make the walking sprites animate thats when the issue started. Starting at exactly //Animation portion. So when i remove that last portion with the //Animation code it goes back to scale normal like this but it just doesnt have his walk (that image flips) and jump animations obviously. so im wondering if that was a bad script to follow?


so thats why im wondering if it was this wall of code i followed to use

GML:
//Animation
if (!place_meeting(x,y+1,oWall))
{
    sprite_index = jPlayer;
    image_speed = 0;
    if (vsp > 0) image_index = 1; else image_index = 0;///the frames of jump
  
}
else
{
    image_speed = 1;
    if (hsp == 0)
    {
        sprite_index = sPlayer;///the idle animation sprites
    }
    else
    {
        sprite_index = wPlayer;///the walk animation sprites
    }
}

if (hsp != 0) image_xscale = sign(hsp);///flips sprite left or right
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
Output the value of image_xscale via show_debug_message. What is its value when it looks okay, what is its value when it looks squished?

The code you posted sets image_index to either -1 or 1. It is not possible for this code to squish a sprite unless you previously applied a scaling factor other than -1 or 1 to both image_xscale and image_yscale. If you're not doing this, the code you posted is not responsible for the issue you're facing.
 

DTheChemist

Member
so its an image import issue? ill re upload the images to be sure. because thats the only code i have for animation motions so far


and where do i put that show_debug_message exactly? i keep getting compiler errors using it next to that x scale.

Another thing i notice is why does my engine always show the Assets browser as the only default instead of "Resources"? did i start my project wrong? as soon as i started and wanted to follow the official channel of Yoyo games tutorials what i was seeing is entirely different. but i just ignored it thinking maybe i have some sort of updated version of the engine.

i see my issue is a sprites importing issue and i dont know how to get around it but delete my entire project and start all over.
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Another thing i notice is why does my engine always show the Assets browser as the only default instead of "Resources"? did i start my project wrong? as soon as i started and wanted to follow the official channel of Yoyo games tutorials what i was seeing is entirely different. but i just ignored it thinking maybe i have some sort of updated version of the engine.
The tutorials you've been following will be made with a previous iteration of the IDE that had a Resource Tree. The new IDE has a the Asset Browser, which is essentially the same thing but with a bit of added functionality (like favourites and tags). You should still be able to follow the same workflow, as the core resources/assets are the same, ie: sprites, tilesets, paths, etc...

so its an image import issue? ill re upload the images to be sure. because thats the only code i have for animation motions so far
No, from the videos I'd say it's absolutely not an import issue. It is almost certainly related the image_xscale value. "image_xscale" is a built in variable that ALL objects in GameMaker have and it is used to set the horizontal scale of the sprite being drawn. In this case it looks like the variable is being set incorrectly.

and where do i put that show_debug_message exactly? i keep getting compiler errors using it next to that x scale.
Add this into the STEP event, AFTER all the code:
GML:
show_debug_message("Xscale = " + string(image_xscale));
show_debug_message("Yscale = " + string(image_yscale));
In the output console (at the bottom of the IDE) you will get a continuous flow of messages, and as you move the player character around you should see the output values change, depending on what you do. So move left and right, jump, etc... and check the output. The Y scale probably should only ever be 1, and the X scale should only ever be -1 (for left) or 1 (for right), and if there are any other values then the issue is definitely that the xscale and/or yscale are being manipulated somewhere in the code.

PS: YYG have just launched an excellent new tutorial series that is incredibly polished and in-depth. I would 100% recommend that you check it out as it uses all the updated features of GMS and will be less confusing than the older tutorials that are available: https://www.yoyogames.com/en/blog/little-town-gamemaker-tutorial

Oh, and maybe check out the youtube channels from @matharoo and @samspade. Both these creators have excellent tutorials.
 

TheouAegis

Member
It looks like the Sprite was resized when placed in the room, either intentionally or accidentally. Thus it's not getting squished, it's getting reset back to normal size.
 

woods

Member
if (hsp != 0) image_xscale = sign(hsp);///flips sprite left or right
TheouAegis

It looks like the Sprite was resized when placed in the room, either intentionally or accidentally. Thus it's not getting squished, it's getting reset back to normal size.
as soon as you move the player, it gets pushed back to original size
 

DTheChemist

Member
@Nocturne thanks for the huge tip post. ill look heavy into those tutorials

Everybody comment is helpful here. However i ended up figuring it out with some help on FB earlier this afternoon before i checked here. Im just now seeing everyone comments here. The code suggested below Fixed the issue but yeah my issue for sure was i resized the player object a bit bigger when i first started in the room and forgot. Im still used to Unity and doing stuff like that. But it was explained to me already and now i know what to do for a code fix or to set the scale x y to 1 -1 for the player object in the room initially and not resize the scales to avoid problems

heres the code i used btw that fixed it that was suggested on FB
Code:
if (hsp != 0) image_xscale = sign(hsp) *abs(image_xscale)
ONLY issue im having now which ill get back to sometime today is the ground land issue. when the character lands it shakes a bit or is twitchy. i assume its a ground code issue?


Thanks to all the replies of help here
 
Last edited:
Top