1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 [SOLVED] Alternatives to draw_sprite_pos?

Discussion in 'Programming' started by skeptile, Feb 15, 2018.

  1. skeptile

    skeptile Member

    Joined:
    Aug 10, 2017
    Posts:
    24
    I'm trying to achieve a card-flipping animation that simulates perspective, so I started off using draw_sprite_pos to skew the sprite. The result I got is this:
    [​IMG]
    See how the card gets distorted in the middle? Everything kind of gets pinched up. According to the manual, this has something to do with the way sprites are drawn as a quad of primitives. Is there any way to avoid this distortion? Or is there some alternative script or function I could be using to achieve this effect more easily? I've tried a few sprite-skewing scripts from the net but I haven't been able to find something that does what I need.

    Thanks for the help!

    (If it helps, here's the step code for flipping the card)
    Code:
    if (flipping == true) {
     flipRads += (pi / room_speed);
     if (flipRads >= pi) {
      flipRads = 0;
      flipping = false;
      reset_card_corners();
      }
     else if (flipRads < pi / 2) {
      x1 = x - sprite_xoffset + (sprite_width/2 * sin(flipRads));
      x2 = x - sprite_xoffset + sprite_width - (sprite_width/2 * sin(flipRads));
      x3 = x2; x4 = x1;
      y1 = y - sprite_yoffset - (flipMaxY * sin(flipRads));
      y2 = y - sprite_yoffset + (flipMaxY * sin(flipRads));
      y3 = y - sprite_yoffset + sprite_height - (flipMaxY * sin(flipRads));
      y4 = y - sprite_yoffset + sprite_height + (flipMaxY * sin(flipRads));
      }
     else {
      if (hasFlipped == false) {
       hasFlipped = true;
       flipped = !flipped;
       if (flipped == true)
        sprite_index = spriteFront;
       else sprite_index = spriteBack;
       }
      x1 = x - sprite_xoffset + (sprite_width/2 * sin(flipRads));
      x2 = x - sprite_xoffset + sprite_width - (sprite_width/2 * sin(flipRads));
      x3 = x2; x4 = x1;
      y1 = y - sprite_yoffset + (flipMaxY * sin(flipRads));
      y2 = y - sprite_yoffset - (flipMaxY * sin(flipRads));
      y3 = y - sprite_yoffset + sprite_height + (flipMaxY * sin(flipRads));
      y4 = y - sprite_yoffset + sprite_height - (flipMaxY * sin(flipRads));
     }}
    
     
  2. zbox

    zbox Member GMC Elder

    Joined:
    Jun 21, 2016
    Posts:
    796
    Someone published a Marketplace asset to fix this, I remember noticing it once because I had had a problem with this too.

    Have a look for it, uses a shader I'm pretty sure.
     
    Lonewolff likes this.
  3. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,207
    Yep, this is correct behavior (as funny as it sounds).

    [​IMG]

    There are a few ways around this.


    I would personally go with the last option. It is an awesome asset and saved me much heartache.

    [edit]
    There is actually a fourth way. 3D perspective camera.

    That would be an even easier option.
     
    Last edited by a moderator: Feb 16, 2018
  4. skeptile

    skeptile Member

    Joined:
    Aug 10, 2017
    Posts:
    24
    Wow! Thanks for the link to that extension. Looks like it's exactly what I need.
    However, it's for GMS 1.4, and I'm using GMS 2. And looking at the forum post, it looks like it's not compatible with GMS2 at all.
    Maybe I'll open it in 1.4 and see if I can work out how to port it to 2. Thanks!
     
  5. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,207
    Yeah, pretty sure it was fine in GMS2.
     
  6. skeptile

    skeptile Member

    Joined:
    Aug 10, 2017
    Posts:
    24
    Yup, I just copied over the shader and script and it works great. Thanks!
     
    Lonewolff likes this.
  7. smmh

    smmh Member

    Joined:
    Aug 4, 2016
    Posts:
    2
    Can you give an example on how to do this? I assume using a primitive_begin creates a vertex buffer, but how would I apply a transform to it?
     

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