Giter VIP home page Giter VIP logo

ios-spritekit-textureatlasanimation's Introduction

iOS-SpriteKit-TextureAtlasAnimation

An useful SKNode subclass that allows to animate a set of sprite frames of an atlas bundle.

ScreenShot

Introduction

Inspired from an interesting tutorial, read on RayWenderLich and written by Tony Dahbura (http://www.raywenderlich.com/45152/sprite-kit-tutorial-animations-and-texture-atlases) about Animations and Texture Atlases, I decide to develop an utility class (SKNode sublass) to achive this behavior in an EZ Way!

How to use

To implement an animation you have:

  1. to add in the main bundle of the project, an atlas bundle with a set of sprite frames (within my example project there are some bundle).
  2. create an instance of the class L3SDKTextureAtlasAnimation an initialite it with one of the init factory methods (see below).
properties
name type description
spriteNode SKSpriteNode gets the SKSpriteNode reference
timePerFrame NSTimeInterval gets/sets the amount of time that each texture is displayed. Default=0.05f
allowSpriteToMoveOn SpriteMovmentDirection gets/sets the motion behavior
spriteOrientation SpriteOrientation gets/sets the original orientation of the sprite frames
methods
name | type | description --------------------------| ----------------|------------------------------------------------------------------- initWithAtlasBundle | instancetype | allows to init the class animateToDirection | void | allows to start the animation and optionally to move toward a direction animate | void | allows to start an animation
enums
//defines the motion direction behavior
typedef enum : NSUInteger {
    SpriteMovmentDirectionAll,
    SpriteMovmentDirectionX,
    SpriteMovmentDirectionY
} SpriteMovmentDirection;
//defines the orientation of the sprite frames
typedef enum : NSUInteger {
    SpriteOrientationRight,
    SpriteOrientationLeft,
    SpriteOrientationUp,
    SpriteOrientationDown
} SpriteOrientation;
example
```objectivec

-(void)setupRedBaron{ //NOTE: this example shows how to setup a custom umber format self.spriteAnimation=[[L3SDKTextureAtlasAnimation alloc] initWithAtlasBundle:@"baroncombo" andTextureBaseName:@"baron_combo" andTextureNumberFormat:@"0000"];

self.spriteAnimation.spriteNode.position=CGPointMake(self.size.width/2,self.size.height/2);;
self.spriteAnimation.spriteNode.size=CGSizeMake(400, 400);
self.spriteAnimation.timePerFrame=0.05f;
self.spriteAnimation.spriteOrientation=SpriteOrientationLeft;

[self addChild:self.spriteAnimation];

}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ CGPoint location = [[touches anyObject] locationInNode:self]; [self.spriteAnimation animateToDirection:location]; }

<br/> 
![ScreenShot](https://raw.github.com/alchimya/iOS-SpriteKit-TextureAtlasAnimation/master/screenshots/CaveMan.gif)
<br/> 
![ScreenShot](https://raw.github.com/alchimya/iOS-SpriteKit-TextureAtlasAnimation/master/screenshots/VikingJump.gif)
<br/> 
![ScreenShot](https://raw.github.com/alchimya/iOS-SpriteKit-TextureAtlasAnimation/master/screenshots/VikingRun.gif)

ios-spritekit-textureatlasanimation's People

Contributors

alchimya avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.