GMS 2 Sprite Character Changes Size When Moving in Room Editor

B

BlueBird02

Guest
Game maker help 3.PNG

I've been trying to add an enemy named Flygito, a small bug enemy. I decided to shrink her sprite down (Picture above) on the room editor, but when I start the game and her sprite started moving, Flygito's sprite size goes wrong.

Game Maker help 4.PNG

But her sprite remains the same when I use her default size (By taking the obj_sprite to the map without changing the size) her sprite doesn't look squashed or weird looking. Just fine.Game maker 3.PNG
But I wanted Flygito to be a small enemy when it moves without making the sprite look "off".

This is her code.

switch (state) {
case "chase":
if not instance_exists(obj_hero) break;

if place_meeting(x, y, obj_hero) and obj_hero.state != "roll" and attacked == false {
create_hitbox(x, y, self, sprite_index, knockback, 1, damage, image_xscale);
attacked = true
}
if attacked == true {
vspeed = -1;
}
break;
}

Game maker help.PNG

Is there a way to change the size of a sprite in Room Editor without making it look "off" when starting a game?
 

samspade

Member
Changes made to an instance of an object in the room editor will not be reset when the game starts unless there is code that does it. I would search through the objects code and look for anything that sets image_xscale. If I were to guess, I would guess that you have a facing or direction type variable that sets image_xscale based on hsp - something like this is common:

Code:
if (hsp != 0) {
    image_xscale = sign(hsp);
}
 
B

BlueBird02

Guest
Changes made to an instance of an object in the room editor will not be reset when the game starts unless there is code that does it. I would search through the objects code and look for anything that sets image_xscale. If I were to guess, I would guess that you have a facing or direction type variable that sets image_xscale based on hsp - something like this is common:

Code:
if (hsp != 0) {
    image_xscale = sign(hsp);
}
All right, Where do I put the code on Flygito's code?

-----------------------
if (hsp != 0) {
image_xscale = sign(hsp);
}

if place_meeting(x, y, obj_hero) and obj_hero.state != "roll" and attacked == false {
create_hitbox(x, y, self, sprite_index, knockback, 1, damage, image_xscale);
attacked = true
}
if attacked == true {
vspeed = -1;
}
break;
}
----------------------

Like this?
 

samspade

Member
All right, Where do I put the code on Flygito's code?

-----------------------
if (hsp != 0) {
image_xscale = sign(hsp);
}

if place_meeting(x, y, obj_hero) and obj_hero.state != "roll" and attacked == false {
create_hitbox(x, y, self, sprite_index, knockback, 1, damage, image_xscale);
attacked = true
}
if attacked == true {
vspeed = -1;
}
break;
}
----------------------

Like this?
I'm sorry. I don't understand your question. My reply was asking if you had code like that already as it would cause the problem you are describing, not suggesting that you use it.

As mentioned in the previous post, if you set the scale of an instance of an object in the room editor, that scale will persist in the game. So if the scale in the game is different than what it is in the room editor, it means you have code in the object which is changing the scale.
 
B

BlueBird02

Guest
I'm sorry. I don't understand your question. My reply was asking if you had code like that already as it would cause the problem you are describing, not suggesting that you use it.

As mentioned in the previous post, if you set the scale of an instance of an object in the room editor, that scale will persist in the game. So if the scale in the game is different than what it is in the room editor, it means you have code in the object which is changing the scale.

AHHHH! I see.

In the step event, I have image_xscale. Could that be the problem?
 

samspade

Member
Your create event is the problem. It says image_xscale = sign(hspeed). The sign function returns 1, -1, or 0 depending upon whether the number is positive, negative, or 0. So in this case you set hspeed to a positive number, then set image_scale to the sign of that number (1) so you set image_xscale to 1.

The solution to this is to not set the image_xscale and instead draw the sprite manually.

Code:
///draw event
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale * sign(hsp), image_yscale, image_angle, image_blend, image_alpha);
Or manually resize the image.
 
B

BlueBird02

Guest
Your create event is the problem. It says image_xscale = sign(hspeed). The sign function returns 1, -1, or 0 depending upon whether the number is positive, negative, or 0. So in this case you set hspeed to a positive number, then set image_scale to the sign of that number (1) so you set image_xscale to 1.

The solution to this is to not set the image_xscale and instead draw the sprite manually.

Code:
///draw event
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale * sign(hsp), image_yscale, image_angle, image_blend, image_alpha);
Or manually resize the image.
I'll try to figure this code out... hopefully
 

nlolotte

Member
You could create a variable like dir = 1.
In the step event you could try:
Code:
if hspeed > 0
{
dir = 1;
}
else
{
dir = -1;
}
image_xscale = dir;
 

samspade

Member
You could create a variable like dir = 1.
In the step event you could try:
Code:
if hspeed > 0
{
dir = 1;
}
else
{
dir = -1;
}
image_xscale = dir;
No they can't. That's the problem they are having. That will set the xscale to be 1 or -1 and it needs to be whatever it is set to (which is something less than one) in the room editor.
 
B

BlueBird02

Guest
No they can't. That's the problem they are having. That will set the xscale to be 1 or -1 and it needs to be whatever it is set to (which is something less than one) in the room editor.
You could create a variable like dir = 1.
In the step event you could try:
Code:
if hspeed > 0
{
dir = 1;
}
else
{
dir = -1;
}
image_xscale = dir;

I still appreciated your help guys.

if your wondering where I get the code is this video.





Maybe this will help, hopefully.
 

samspade

Member
I've already answered the question. You can't use the code I pointed out if you want to adjust the scale in the room editor.
 
Last edited:
Top