playMaker

Author Topic: Trying to Flip a Sprite  (Read 3564 times)

CriticalGames

  • Playmaker Newbie
  • *
  • Posts: 2
Trying to Flip a Sprite
« on: April 05, 2014, 01:26:30 AM »
Hi everyone,

I'm new to Playmaker, and I'm having a bit of trouble, so I hope that someone might be able to help out.

I'm trying to create a basic movement system for a 2D platformer. The character is a Sprite. I have the idle and walking animations working alright, but I'm having a lot of trouble trying to make the sprite flip whenever the player changes direction.

By using the Set Scale action with some events (as seen below), I've got my character flipping back and forth. Initially I was getting that dreaded 'exceeded maximum number of loops' error, so that's why there's a 'Do Nothing' state with a 'Next Frame Event' at the top of the FSM.

Anyway, so I've got the visual element working (the character does flip), but now it's causing troubles with my movement. Without the Set Scale action, he moves as smooth as butter. But with it on, he slows down considerably and gets quite choppy.

Below I have included two images showing how I've got the 'Flip Sprite' FSM set up. If anyone's wondering about my movement system, I've just got a simple combination of 'Get Axis' and 'Set Velocity 2D' actions.

If anyone could tell me why it would be making movement choppy, or how to fix the issue, it would be sincerely appreciated. Thanks in advance!




Moza

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Trying to Flip a Sprite
« Reply #1 on: April 06, 2014, 10:08:38 PM »
Just an idea and I could be totally wrong as Im very new to Playmaker also but have you tried maybe just using the Rotate action to simply Rotate the sprite on the Y axis to flip it, instead of using Set Scale?

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Trying to Flip a Sprite
« Reply #2 on: April 06, 2014, 10:48:09 PM »
Move the float compare into the flip states.

State 1 - Sets scale to -1(not everyframe) and check (everyframe) if the axis is greater than (moves to state 2)
State 2 - Sets scale to 1(not everyframe) and check (everyframe) if the axis is less than (moves to state 1)

Hope that helps
« Last Edit: April 07, 2014, 12:17:07 AM by LampRabbit »

CriticalGames

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Trying to Flip a Sprite
« Reply #3 on: April 25, 2014, 04:19:35 AM »
Hi guys,

I'm sorry it took me so long to reply. I saw your replies a couple of weeks ago and started to test them out, but got sidetracked and forget about it. It's a bit belated, but thanks a lot for the help!

@Moza - A good suggestion, but I'm afraid it doesn't work very well. You see the sprite physically rotating - kind of like the spin attack from Paper Mario. Thanks though!

@LampRabbit - Great idea! It's working much better now, so I'm definitely on the right track. I had to keep the 'Do Nothing' state around as otherwise I still get the 'exceeded maximum number of loops' error, but he does now flip back and forth while walking. The only problem is that whenever he stops walking, he flips back to the right, which looks pretty jarring. I've been trying to get it working, but no luck so far - all I can make him do is turn back to the left or right every time he stops, rather than it being based on his previous movement direction. If you have any more solutions, I'd be very grateful.

Regardless, thanks again for the help!  ;D