CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage("hero.png"); CCSpriteFrame *frame0 = CCSpriteFrame::createWithTexture(pTexture, CCRectMake(0,0,32,32)); CCSpriteFrame *frame1 = CCSpriteFrame::createWithTexture(pTexture, CCRectMake(32,0,32,32)); CCSpriteFrame *frame2 = CCSpriteFrame::createWithTexture(pTexture, CCRectMake(64,0,32,32)); CCSpriteFrame *frame3 = CCSpriteFrame::createWithTexture(pTexture, CCRectMake(96,0,32,32)); CCArray *animFrames = CCArray::create(); animFrames->addObject(frame0); animFrames->addObject(frame1); animFrames->addObject(frame2); animFrames->addObject(frame3); CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.2f); CCSprite *heroSprite0 = CCSprite::createWithSpriteFrame(frame0); //CC_BREAK_IF(!heroSprite0); heroSprite0->setPosition(ccp(100,100)); this->addChild(heroSprite0,1); CCAnimate *animate = CCAnimate::create(animation); heroSprite0->runAction(CCRepeatForever::create(animate)); //next is for the animation2 CCAnimation *animation2 = CCAnimation::create(); for(int i=1;i<19;i++) { char *tt = new char[3]; memset(tt,0,3); std::string s; if(i<10) { itoa(i,tt,10); s="fish00" + std::string(tt); } else { itoa(i,tt,10); s="fish0" + std::string(tt); } s=s+".png"; CCTexture2D *playerRunTexture = CCTextureCache::sharedTextureCache()->addImage(s.c_str()); CCSpriteFrame *fishFrame = CCSpriteFrame::createWithTexture(playerRunTexture, cocos2d::CCRectMake(0,0,100,100)); animation2->addSpriteFrame(fishFrame); delete []tt; } animation2->setDelayPerUnit(0.2f); CCAnimate *action = CCAnimate::create(animation2); CCTexture2D *playerRunTexture0 = CCTextureCache::sharedTextureCache()->addImage("fish001.png"); CCSprite *p = CCSprite::createWithSpriteFrame(CCSpriteFrame::createWithTexture(playerRunTexture0, cocos2d::CCRectMake(0,0,100,100))); p->setPosition(ccp(200,200)); this->addChild(p,1); p->runAction(CCRepeatForever::create(action)); CCMoveBy *moveBy = CCMoveBy::create(1.0f,ccp(100,50)); p->runAction(CCRepeatForever::create(moveBy));