如何在coCos2d-x中调整动画精灵的大小 [英] How to resize the the animating sprite in cocos2d-x

查看:0
本文介绍了如何在coCos2d-x中调整动画精灵的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改动画雪碧的大小。我怎么能这样做呢?我试图使用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); 

推荐答案

尝试如下。它工作正常。

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);

这篇关于如何在coCos2d-x中调整动画精灵的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆