Dana
Dana

Reputation: 21

Sprite Animation error in cocos2d-x

Why animation from the line 2 appears as an error "Function 'animation' cannot be resolved" ?

CCSprite * sprite  = CCSprite::create("start.png");
CCAnimation * anim = CCAnimation::animation();
anim->addSpriteFrameWithFileName("start.png");
anim->addSpriteFrameWithFileName("take.png");
anim->addSpriteFrameWithFileName("action.png");

anim->setLoops(1);
anim->setDelayPerUnit(0.1f);

sprite->runAction(CCAnimate::create(anim));
sprite->setPosition(ccp(450,425));
this->addChild(sprite, -1);
float cX = size.width / sprite->getContentSize().width/1.8;
float cY = size.height / sprite->getContentSize().height/1.2;
sprite->setScaleX(cX);
sprite->setScaleY(cY);

Upvotes: 0

Views: 209

Answers (2)

KARTHIK  RA
KARTHIK RA

Reputation: 469

try this code:

  sprite->setPosition(ccp(450,425));
  this->addChild(sprite, -1);

 // after this code
 sprite->runAction(CCAnimate::create(anim));

Upvotes: 0

nomann
nomann

Reputation: 2267

You seem to be using older code with newer cocos2d-x version. Please replace animation() with create().

Upvotes: 1

Related Questions