Legacy GM I need a flip effect when changing direction

  • Thread starter fawfulthegreat64
  • Start date
F

fawfulthegreat64

Guest
So I've almost got my basic movement down for my characters, except two things, one of which I'm currently already getting help with, and the other thing is this: One of my playable characters is flat (he is Paper Mario of course). I can already make him walk smoothly in every direction, but he needs to have a flip effect when turning around.

I don't want the effect for every single direction change though, just when he goes from an up direction to a down direction, or from a left direction to a right direction. Anything else would result in the sprite being the same before and after the flip (needless flipping basically)
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You could possibly use the draw_sprite_pos function and change the actual primitive points that are used to draw the sprite to get a flip? Alternatively, you'd want to look at creating your own textured primitive, using the 3D transform functions, or perhaps a shader...
 
T

TDSrock

Guest
makeing image_xscale negative flips it horizontally and making image_yscale negative flips it vertically. Note that you'll want your characters origin at the center of the sprite otherwise some interesting things start happening as you flip around the origin point, which you define.

To get a nice flipping animation is a bit tougher.

Nocturn proposes some good solutions that should be doable. Of-course you could always add in some extra sprites to do the job.
 
F

fawfulthegreat64

Guest
My original idea was to make sprites of the character getting thinner and thinner (simulating the frames of a flip) but I wouldn't know where to code those in. Also do these solutions work for transitioning between two different sprites? Because the next character I need to give the effect to has a letter on his cap that would otherwise be backwards unless I give him a separate sprite for left/right.

One more thing: All my characters currently have origins at the bottom of the sprite (horizontally centered). Is this wrong? I did it because the ground would be at the bottom of the character's feet, and if I ever made them do anything relative to the ground (like jump) I'm thinking I'd need that, right?
 
T

TDSrock

Guest
It's not wrong, putting the sprite's origin is in essence up to you, however if you want to work with x and y scale, you'll probably want them in the center.

I get that what your trying to do is make a paper mario/mario rpg clone? I think the easiest way to achieve the flip is to recognize the moment you need to flip, start the flipping animation(from a sprite_index) then once the flip is done swap it with the correct sprite_index for the new facing direction.
 
F

fawfulthegreat64

Guest
Yes, it's a fangame inspired by Mario & Luigi: Paper Jam (so it mixes the art styles of Mario & Luigi and Paper Mario)

I found this, but all it does when added to my game is make Paper Mario (oddly) stretch horizontally with no flip effect. In the sample game that came with it, Paper Luigi was only able to move left and right, but his turns were the exact effect I need.

How do I recognize the moment the animation is needed? I'm still new to coding so when I play with code I frequently get errors or odd effects (such as a character moving in the idle animation almost as if he was floating)
 

wamingo

Member
if it's becoming stretched either your xscale went over 1 or under -1, or your sprite/origin isn't centered.

Code:
// LR becomes -1 if press left, 1 if press right, 0 if either no keys or both keys
var LR = keyboard_check(vk_right) - keyboard_check(vk_left)

if LR==-1{
  face=0
  x-=3
  sprite_index = spr_run
}else if LR==1{
  face=1
  x+=3
  sprite_index = spr_run
}else{
  sprite_index = spr_idle
}

if (face=0 && image_xscale>-1)
  image_xscale = max(image_xscale - 0.2, -1)   // limits the xscale
if (face=1 && image_xscale<1)
  image_xscale = min(image_xscale + 0.2, 1)
 
F

fawfulthegreat64

Guest
My run and idle sprites are split into different sprites for each direction. Which ones do I use for the sprite_index values in that code?

Edit: Tried skipping that part due to the above and got a stretched Paper Mario again.

 

wamingo

Member
Well why didn't you mention that you already had sprites for both directions? :)
Are they very important to you? Many games just flip the one sprite.

But I'm trying to whip something up, give me a bit...
 
F

fawfulthegreat64

Guest
You're right that I can flip the right facing sprite to get the left. But I can't do that with the up sprite and the down sprite (and when I add Paper Luigi I can't just flip him because of the L on his cap)
 

wamingo

Member
Well I'm not doing the up/down for you, but adding it in shouldn't be impossible:

Code:
///CREATE
Face=1
Flip=Face

///STEP
var moving=false

LR = keyboard_check(vk_right) - keyboard_check(vk_left)
if LR==-1{
  Flip=0
  x-=3
  moving=true
}else if LR==1{
  Flip=1
  x+=3
  moving=true
}


if (Flip!=Face)  // decrease xscale to 0
{
  image_xscale = max(image_xscale - 0.2, 0)
  if (image_xscale==0)
  {
    Face=Flip
  }
}
else if (image_xscale<1)  // grow back from 0
{
  image_xscale = min(image_xscale + 0.2, 1)
}

if (moving){
  if (Face==0) sprite_index = spr_run_left
  else  sprite_index = spr_run_right
}else{
  if (Face==0) sprite_index = spr_idle_left
  else  sprite_index = spr_idle_right
}
You could make up/down be Flip=2 and Flip=3. Then check for that after the Flip!=Face, flip the yscale as well, etc. Doable I think.
 
F

fawfulthegreat64

Guest
Now he flips left and right, but is still stretched and lost his walking animation for up. I removed that last bit of code and he regained the ability to walk upward but it still stretched and the flip animation flips to the same sprite before changing directions.

Also it may be worth noting that in the create event for Paper Mario I dragged and dropped a size change so his size is 0.6. This is because his normal size is too big (and I don't want to make it smaller in image editor because then it blurs or looks choppy)

Here's a bad gif of my problem:
 
Last edited by a moderator:

wamingo

Member
yes it is worth noting!
see if this helps with the initial scale
Code:
else if (image_xscale<0.6)  // grow back from 0
{
  image_xscale = min(image_xscale + 0.2, 0.6) //max 0.6
}
You need to wack away at the up/down for a while yourself.
But if you're only interested in xscale flip and not yscale, then it may be easier than you think. Pay attention to the last section.
 
F

fawfulthegreat64

Guest
He flips fine now, but lost his run animation for up and down. I don't think I need any more flipping, I just want his up and down animations fixed at this point.
 
T

TDSrock

Guest
I see that Wamingo has provided you with a ton of code. It'll probably be a better idea to work on it on your own now fawfulthegreat64, if you don't understand the code you won't know exactly what happens, so if you ever run into an odd bug regarding this you won't know where things are wrong exactly.

I rarely give people code that will just work. I have and always be against it for two reasons:
1: The user I am helping might not understand it and will run into extremely similar issues and come to us instead of having learnt from the experience last time.
2: It takes cost me quite some more time to write out the code versus(potentially several times as you might come back) then take the effort to solve the issue and similar issues permanently for the user.

I have provided a large amount of example code in the past where I deal with the issue in a somewhat similar issue(view previous posts on this and the old forum. I've also provided the .gmz for a prototype I made Vilom Chronicles, I've added a link to the page on these forums some time ago so anyone may view it, and view how we exactly dealt with our problems. Which could be a great learning experience if taken the time to go through it.
 
Top