hello everyone,
I am trying to create my own Prototype class in generating basic animation
#include "cocos2d.h"
using namespace cocos2d;
spriteObject::spriteObject(const char* spriteFile, float x, float y)
{
sprite = CCSprite::spriteWithFile(spriteFile);
sprite->setPosition(ccp(x,y));
}
class spriteAnimateMovementDirection : public CCLayer
{
public:
CCRepeatForever* repeat;
//spriteAnimateMovementDirection(const char* spriteFile, ...);
spriteAnimateMovementDirection(const char* sprite1, const char* sprite2);
private:
CCMutableArray* animationFrames;
CCMutableArray* spriteAnimationFiles;
};
spriteAnimateMovementDirection::spriteAnimateMovementDirection(const char* sprite1, const char* sprite2)
{
CCTexture2D* texture;
CCRect textureRect;
CCSpriteFrame* spriteFrame;
CCAnimate* animate;
CCAnimation* animation;
texture = CCTextureCache::sharedTextureCache()->addImage(sprite1);
textureRect = CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height);
spriteFrame = CCSpriteFrame::frameWithTexture(texture,textureRect);
animationFrames->addObject(spriteFrame);
texture = CCTextureCache::sharedTextureCache()->addImage(sprite2);
textureRect = CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height);
spriteFrame = CCSpriteFrame::frameWithTexture(texture, textureRect);
animationFrames->addObject(spriteFrame);
animation = CCAnimation::animationWithFrames(animationFrames,0.2f);
animate = CCAnimate::actionWithAnimation(animation);
repeat = CCRepeatForever::actionWithAction(animate);
}
so on the helloworldscene.cpp
#include "HelloWorldScene.h"
#include "MyClass.h"
using namespace cocos2d;
spriteObject* hero;
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::node();
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::node();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
spriteObject hero("heroDownStand.png",100,100);
this->addChild(hero.sprite);
spriteAnimateMovementDirection moveUp("heroDownWalk1.png", "heroDownWalk2.png");
hero.sprite->runAction(moveUp.repeat);
return true;
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
// "close" menu item clicked
CCDirector::sharedDirector()->end();
}
after compiling the simulator doesn’t show up but there where no error on the compilation.