第八节一个动画的设计

这节粘上一段代码吧, 一个动画的代码。这个在调试中发现一个问题
CCSpriteFrame::createWithTexture 参数,在具体拿时出现问题,最后发现是平台给了一个计算的缩放比
率,导致了真正的图片大小提供的便不会准确。
CCTexture2D *pTexture=CCTextureCache::sharedTextureCache()->addImage("3.png");
CCSpriteFrame *frame0=CCSpriteFrame::createWithTexture(pTexture,CCRect((float)(0),
(float)(0), (float)(32), (float)(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();
//CC_BREAK_IF(!animFrames);
animFrames->addObject(frame0);
//animFrames->addObject(frame1);
//animFrames->addObject(frame2);
//animFrames->addObject(frame3);
CCAnimation *animation=CCAnimation::createWithSpriteFrames(animFrames,0.2f);
//CC_BREAK_IF(!animation);
CCSprite *heroSprite0=CCSprite::createWithSpriteFrame(frame0);
//CC_BREAK_IF(!heroSprite0);
heroSprite0->setPosition(ccp(100,100));
addChild(heroSprite0,3);
CCAnimate *animate=CCAnimate::create(animation);
heroSprite0->runAction(CCRepeatForever::create(animate));//一直执行下去

你可能感兴趣的:(android,cocos2dx,实例剖析)