• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] Alternatives to draw_sprite_pos?

S

skeptile

Guest
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:

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));
 }}
 

zbox

Member
GMC Elder
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.
 
L

Lonewolff

Guest
Yep, this is correct behavior (as funny as it sounds).



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:
S

skeptile

Guest
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!
 
L

Lonewolff

Guest
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!
Yeah, pretty sure it was fine in GMS2.
 
Top