Skip to content

Latest commit

 

History

History
executable file
·
133 lines (84 loc) · 5.4 KB

README.markdown

File metadata and controls

executable file
·
133 lines (84 loc) · 5.4 KB

TDAnimEngine

Description

TDAnimEngine allows you to create cut-out characters and animations in Maya an export it to be use directly into Cocos2D through XML. It's not a sprite based tool. It's for characters made out different pieces that will animate rotating its different components.

The library is composed of two parts:
. Maya Scripts: containing 1 script to export the character and 1 script to export the animations
. XCode lib: the TDAnimEngine classes to be added to your XCode project

What you can do:
. Create a character in Maya and recreate it in Cocos2D (including Z-depth, rotations and parenting)
. Access the different pieces using from Cocos2D using the same name that you used in Maya
. Use SpriteSheets instead of pngs
. Create rotation based animation in Maya and apply them to your character in Cocos2D
. Control events when an animation has looped, has stopped, etc
. Define custom events that will be launch at specific frames . Add Maya Locators to your object so you can easily add extra objects at those positions inside Cocos2d

Dependencies:

TBXML is needed to parse the generated XML files.
Get it here: TBXML

General Usage

##Maya Scripts##

MayaToCocos2DNodes.mel: use this script on a Maya model (made out of polygonal planes) to generate an XML that will contain all the necessary information to recreate it on Cocos2D. Use a 1/100 ratio to recreate the different pieces (ie: if an image it's 200x200 pixels, in Maya you should create a plane 0.2 x 0.2).

Please visit the tutorial for a detail explanation on how to use this script.

MayaAnimToXMLNodeBased.mel: use this script to, having a model in Maya, create a rotation based animation (or Direct Kinematics) and export it as XML so it can be used on Cocos2D. So far, we've worked out just rotations. In a future we might support translation and scales.

Please visit the tutorial for a detail explanation on how to use this script.

##TDAnimEngine Lib##

It's composed of a number of classes. The main one is:

TDAnimCharacter: this is the class responsible of creating the different CCSprites the character might be made of. Extend this class when having multiple characters in one scene for easier control.

###RECREATING THE CHARACTER### There are two ways of recreating a character based on the XML generated in Maya:

PNG'S BASED

TDAnimCharacter *robot = [TDAnimCharacter characterFromConfigFile:"FILENAME"];
[robot setPosition:ccp(120, 120)];
[self addChild:robot];

It requires you have included in your Resources the same PNGs used in Maya to create the character. The class will load them as textures of the recreated CCSprites.

SPRITESHEET BASED

TDAnimCharacter *robot = [TDAnimCharacter characterFromConfigFile:"FILENAME" andAtlasInfoFile:"FILENAME"];
[robot setPosition:ccp(120, 120)];
[self addChild:robot];

It requires you have a SpriteSheet png for the character and it's generated PLIST with the same name.

###USING LOCATOR SUPPORT###

Maya Setup: Follow the same steps as setting up a plane, but use a locator instead, parent the locator to whatever you want it to follow. Make sure you select it when you run the export script.

Cocos2d Setup: When you want to add a sprite to the locator inside cocos2d you simply need to run the following code:

CCNode *Locator = (CCNode *)[robot getPointByName:@"myLocator"];
CCSprite *hat = [CCSprite spriteWithSpriteFrameName:@"RobotHat.png"];
[Locator addChild:hat];

###IMPORTING ANIMATIONS### To import animations to your character use:

[robot createCharacterAnimationsFromXML:"FILENAME"];

The animations can be in the same XML file than the character config XML. We recommend to keep them in different files so the Config file can be reused.

To play an animation:

[robot playAnimation:"ANIMATION NAME" loop:(YES/NO) wait:(YES/NO)];

Where:
ANIMATION NAME: the name of the animation as you set it up on the Maya script
LOOP: will the character repeat the animation over and over?
WAIT: will the character wait until the current animation being played finishes?

CUSTOM EVENTS

You can add custom events to your animation file.
The events are animation specific, meaning that you can define events for the "walk" cycle or for the "jump" cycle.
Example:

<events>
	<animation id="walk">
		<event type="big_step" frame ='1' />
		<event type="small_step" frame ='10' />
		<event type="big_step" frame ='22' />			
	</animation>
</events>

To use the events:

create your own class extending from TDAnimCharacter

interface MyRobot : TDAnimCharacter

On the implementation, overwrite executeEvent method:

-(void) executeEvent:(TDAnimEvent *)_evt
{
	if ([_evt.type isEqualToString:@"big_step")
		self.position = ccpAdd(self.position, ccp(100, 0));
		
	if ([_evt.type isEqualToString:@"small_step"])
		self.position = ccpAdd(self.position, ccp(20, 0));			
}

So, when you play the animation "walk" and the playhead gets to frame 1 and 22, your character will move the right by 100px. It will move 20px when the playhead hits the frame number 10.

Take a look at the example. It includes the Maya files, the TBXML library, the required pngs and the XCode project.

We will add more tutorials as we can.

The Dam Armada