0

我想更改正在动画的 Sprite 的大小。我怎样才能做到这一点 ?我试图通过使用 setScale 属性来改变它的大小,但它在这里不起作用。我在哪里做错了?

CCArray* frames = CCArray::createWithCapacity(3);
CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();


char file[100] = {0};
for (int i = 0; i < 3; i++)
{
    sprintf(file, "bird%d.png", i);
    CCSpriteFrame* frame = frameCache->spriteFrameByName(file);
    frames->addObject(frame);
}

CCAnimation* animation = CCAnimation::createWithSpriteFrames(frames, 0.1);
CCAnimate* animate = CCAnimate::create(animation);
CCRepeatForever* repeat = CCRepeatForever::create(animate);

bird->runAction(repeat);
bird->setScale(0.7); 
4

1 回答 1

3

像这样试试。它工作正常。

CCSprite* pSprite = CCSprite::create("pic2.png");
pSprite->setPosition( ccp(size.width/2, size.height/2) );
this->addChild(pSprite, 0);

//Animation
CCAnimation *animate = CCAnimation::create();
for (int i = 1; i <=3; i++)
{
  char frameName[128] = {0};
  sprintf(frameName, "pic%d.png", i);
  animate->addSpriteFrameWithFileName(frameName) ;
}

animate->setDelayPerUnit(0.1f); // This animation contains 3 frames, will continuous 2.8 seconds.
animate->setRestoreOriginalFrame(true); // Return to the 1st frame after the 3rd frame is played.

CCAnimate *animaction = CCAnimate::create(animate);
CCRepeatForever *reptaction = CCRepeatForever::create(animaction);
pSprite->runAction(reptaction);
pSprite->setScale(0.3);
于 2014-06-01T11:37:44.300 回答