playMaker

Author Topic: 2D Toolkit Custom FlipX Action  (Read 1858 times)

fimmfingur

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
2D Toolkit Custom FlipX Action
« on: October 26, 2012, 03:18:12 AM »
Just made a new one. This is for the 2D ToolKit FlipX() function. I'm sure most of you already have a better solution, but I didn't find one on this forum so I just made my own.

I posted a picture about how to use it.

1) First I set a variable
2) I named mine Flip because that's the only function it will be used for.
3) I set the value of the int to 0. 0 being the "original" flip direction. on this animation, its left.
4) My states look like this.
5) My right states has these action.
6) First i selected the variable the action has to check
7) Here is a basic If statement and IF the flip variable is 0 (which is left for me) it does the .FlipX() to flip the animation.
8) If the character was flipped, the action sets the flip variable to 1 (1 being right for me)
9) Next is the left side
10) Flip variable is selected like before
11) and in this if the flip var is set to 1 the action will make the animation flip to the other side
12) And now if the animation was flipped the action will set the Flip var to 0 again.

This works like a charm for me. And hopefully someone else is looking for something like this :)

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("2D ToolKit/Sprite")]
    [Tooltip("Flips the sprite animation. \nNOTE: The Game Object must have a tk2dAnimatedSprite attached.")]
    public class Tk2dFlipX : FsmStateAction
    {
        [RequiredField]
        [Tooltip("The Game Object to work with. NOTE: The Game Object must have a tk2dAnimatedSprite component attached.")]
        [CheckForComponent(typeof(tk2dAnimatedSprite))]
        public FsmOwnerDefault gameObject;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        public FsmInt intFlipVariable;
        public FsmInt ifFlipVarIs;
        public FsmInt setInt;

        tk2dAnimatedSprite anim;

        public override void Reset()
        {
            gameObject = null;
            intFlipVariable = null;
            ifFlipVarIs = null;
            setInt = null;
        }

        public override void OnEnter()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
            anim = go.GetComponent<tk2dAnimatedSprite>();
            FlipSprite();
        }

        void FlipSprite()
        {
            if (intFlipVariable.Value == ifFlipVarIs.Value)
            {
                anim.FlipX();
                intFlipVariable.Value = setInt.Value;
                return;
            }
            else
            {
                return;
            }
        }
    }

}

midnight_stories

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Re: 2D Toolkit Custom FlipX Action
« Reply #1 on: December 15, 2012, 03:25:45 AM »
Thanks this will be a great help !!!
As soon as I figure out how to add it to the actions.
Cheers