1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 Sprite Character Changes Size When Moving in Room Editor

Discussion in 'Programming' started by BlueBird02, Mar 15, 2019.

  1. BlueBird02

    BlueBird02 Member

    Joined:
    Jul 25, 2016
    Posts:
    52
    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?
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,822
    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);
    }
    
    
     
    BlueBird02 likes this.
  3. BlueBird02

    BlueBird02 Member

    Joined:
    Jul 25, 2016
    Posts:
    52
    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?
     
  4. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,822
    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.
     
    BlueBird02 likes this.
  5. BlueBird02

    BlueBird02 Member

    Joined:
    Jul 25, 2016
    Posts:
    52

    AHHHH! I see.

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

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,822
    Without seeing your code I can't say for sure, but most likely yes.
     
  7. BlueBird02

    BlueBird02 Member

    Joined:
    Jul 25, 2016
    Posts:
    52
    game maker help 5.PNG
    Here's an image!
     
  8. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,822
    No, that wouldn't do anything as it doesn't set image_xscale. What's the code in the create event and the end step event?
     
  9. BlueBird02

    BlueBird02 Member

    Joined:
    Jul 25, 2016
    Posts:
    52
    game maker 6.PNG

    game maker 7.PNG
     
  10. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,822
    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.
     
    BlueBird02 likes this.
  11. BlueBird02

    BlueBird02 Member

    Joined:
    Jul 25, 2016
    Posts:
    52
    I'll try to figure this code out... hopefully
     
  12. nlolotte

    nlolotte Member

    Joined:
    Aug 3, 2016
    Posts:
    458
    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;
     
    BlueBird02 likes this.
  13. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,822
    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.
     
    BlueBird02 likes this.
  14. BlueBird02

    BlueBird02 Member

    Joined:
    Jul 25, 2016
    Posts:
    52

    I still appreciated your help guys.

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






    Maybe this will help, hopefully.
     
  15. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,822
    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: Mar 17, 2019
    BlueBird02 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice