#import "HelloWorldLayer.h"
using namespace artpig;
using namespace std;
// HelloWorldLayer implementation
@implementation HelloWorldLayer
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init
{
// Try to test with different values of the test variables.
bool testRepeatRotation = false;
bool testRepeatMove = false;
bool testFinishRecovery = false;
bool testAutoreverse = false;
bool testAutoreverseDelay = false;
bool testRandomPosition = false;
bool testDisableRotation = false;
bool testDurationChange = false;
if( (self=[super init])) {
/** Get the resource manager with project ID 'pigrun'. The returned
resource manager value is managed by APSResourceManager class, and it
must not be deleted by 'HelloWorldLayer.mm'
*/
APSResourceManager *manager = APSResourceManager::getResourceManagerForProjectId("pigrun");
if (manager) {
// Allocate and initialize a new symbol by resource manager.
_symbol = manager->newSymbol();
if (_symbol) {
////////////////////////////////////////////////////////////
// Customization
////////////////////////////////////////////////////////////
APSRotationAction *rotate = dynamic_cast<APSRotationAction *>(_symbol->getResourceForTag("rotate"));
if (rotate) {
if (testRepeatRotation) {
// Rotate continuously.
rotate->setRepeat(INT32_MAX);
}
if (testDisableRotation) {
rotate->setEnabled(false);
}
}
// Custom bezier move action.
APSBezierMoveAction *move = dynamic_cast<APSBezierMoveAction *>(_symbol->getResourceForTag("move"));
if (move) {
if (testFinishRecovery) {
move->setFinishRecovery(true);
}
if (testRepeatMove) {
move->setRepeat(2);
}
if (testAutoreverse) {
move->setAutoReverse(true);
if (testAutoreverseDelay) {
move->setAutoReverseDelay(1.f);
}
}
if (testRandomPosition) {
time_t t;
time(&t);
srandom(t);
vector<APSAnchor *> *anchors = move->getAnchors();
for (int i=1; i < anchors->size(); i++) {
APSAnchor *anc = anchors->at(i);
CCPoint p = anc->getPosition();
p.x += random()%400-200;
p.y += random()%200-100;
anc->setPosition(p);
p = anc->getBackHandle();
p.x += random()%400-200;
p.y += random()%200-100;
anc->setBackHandle(p);
p = anc->getFrontHandle();
p.x += random()%400-200;
p.y += random()%200-100;
anc->setFrontHandle(p);
}
}
if (testDurationChange) {
move->setDuration(move->getDuration()*2);
}
} // if(move)
////////////////////////////////////////////////////////////
// Set symbol's scale value to fit into the current screen.
_symbol->setScale(manager->getScaleModelToDevice());
// Preload all required data so that the animation runs without delay.
_symbol->preloadData();
// Add symbol's root CCNode object as a child of HelloWorldLayer.
[self addChild:_symbol->getRootNode()];
// Trigger prologue action groups.
_symbol->triggerPrologueActionGroups();
} // if(symbol)
}
}
return self;
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
if (_symbol) {
delete _symbol;
}
APSResourceManager::removeResourceManagerForProjectId("pigrun");
// don't forget to call "super dealloc"
[super dealloc];
}
@end