SKSprite.startAnimation C# (CSharp) Method

startAnimation() public method

public startAnimation ( string name ) : void
name string
return void
    public void startAnimation( string name )
    {
        // if we dont have this one loaded yet, load it up
        if( animations == null || !animations.ContainsKey( name ) )
            preloadAnimations( name );

        if( currentAnimation == null )
            currentAnimation = new SKSpriteAnimation( this );

        currentAnimation.animationState = animations[name];
    }

Usage Example

Esempio n. 1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            _caveManDude.faceBackwards();
            _caveManDude.startAnimation("walk");
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            _caveManDude.faceForwards();
            _caveManDude.startAnimation("walk");
        }

        if (Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.LeftArrow))
        {
            if (_caveManDude.currentAnimation != null)
            {
                _caveManDude.currentAnimation.stop();
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            _caveManDude.startAnimation("hit");
        }
    }