SOLVED draw_sprite_part: drawing from bottom to a rising top

Discussion in 'Programming' started by Bentley, Jan 7, 2018.

Tags:
  1. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    When the player is spawned, I want draw_sprite_part to draw the player 1 pixel at a time. I want it to start at his feet, and rise until his head is drawn. In other words, I want to draw a 1 pixel high rectangular area at his feet (the bottom of the sprite), and increase the size of that rectangular area until it is at his head (the top of the sprite). The whole sprite will be drawn at the end.

    The code I have draws him from his feet first, but draws his feet moving downward. I don't want his feet to move, and I want the rest of the sprite to be drawn upward from his feet.
    Code:
    var x1, y1, x2, y2;
    x1 = 0;
    x2 = sprite_width;
    y1 = sprite_height - y_count; // Draw the sprite, 1 px at a time, starting from his feet and ending at his head
    y2 = sprite_height;
    draw_sprite_part(spr_player, 0, x1, y1, x2, y2, x, y);
    if (y_count < sprite_height)
    {
        y_count++;
    }
    
    Does anyone where I'm going wrong? Thanks for reading.
     
    Last edited: Jan 8, 2018
  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,399
    Subtract y_count from y in your draw function. I think that would do it. If his feet are moving downward, subtracting a value each step should make them move back up to compensate.
     
    Bentley likes this.
  3. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    Wow, that works. Thanks obscene. I would never have guessed that.
     
    obscene likes this.
  4. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,399
    Sometimes I luck up and get one.
     
    Bentley likes this.
  5. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    Haha
     
  6. alib0ng0

    alib0ng0 Member

    Joined:
    Nov 28, 2018
    Posts:
    13
    Do you have some completed code for this please? - I'm trying to achieve a similar effect
     
  7. Lady Glitch

    Lady Glitch Member

    Joined:
    Feb 10, 2019
    Posts:
    20
    I advise you to re-read this thread :)
    Code:
    var x1, y1, x2, y2;
    x1 = 0;
    x2 = sprite_width;
    y1 = sprite_height - y_count; // Draw the sprite, 1 px at a time, starting from his feet and ending at his head
    y2 = sprite_height;
    draw_sprite_part(spr_player, 0, x1, y1, x2, y2, x, y-y_count);
    if (y_count < sprite_height)
    {
       y_count++;
    }
     
  8. alib0ng0

    alib0ng0 Member

    Joined:
    Nov 28, 2018
    Posts:
    13

    Ok, my bad, I was trying to add it to the if statement - thanks!

    Let's say I wanted to reverse this - i.e. start from the top how would that work?
     
  9. Lady Glitch

    Lady Glitch Member

    Joined:
    Feb 10, 2019
    Posts:
    20
    This should do it
    Code:
    y_count = sprite_height;
    Code:
    var x1, y1, x2, y2;
    x1 = 0;
    x2 = sprite_width;
    y1 = 0;
    y2 = sprite_height-y_count;
    draw_sprite_part(spr_player, 0, x1, y1, x2, y2, x, y);
    if (y_count > 0)
    {
       y_count--;
    }
     

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