0

I want to change the size of a Sprite which is animating. How can I do this ? I tried to change its size by using setScale property but it is not working here. where I am doing wrong ?

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); 
Ahmad dar
  • 81
  • 1
  • 14
  • Why did you ask twice: http://stackoverflow.com/questions/23947736/change-scale-of-animating-sprite-in-cocos-2d-x – GameDeveloper May 30 '14 at 14:03
  • @GameDeveloper no one is answering me no anyone want to help me. just ask useless queries instead of helping me. – Ahmad dar May 30 '14 at 19:20
  • @GameDeveloper Do you know the ans of my question ? – Ahmad dar May 30 '14 at 19:22
  • nobody is answering because you are braking the rules by posting multiple times. It also shows that you are simply posting here for an answer and not trying to help yourself. `setScale()` should be working but don't you want to `setScale` on the SpriteFrames you made? – GameDeveloper May 30 '14 at 20:56
  • @GameDeveloper Mr GameDeveloper answer should be like this as Sri answered me and helps me. Thankyou too for giving your precious time to me. – Ahmad dar Jun 01 '14 at 12:30

1 Answers1

3

Try like this. It's working fine.

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);
Sasivarnan
  • 532
  • 6
  • 11
Sri
  • 827
  • 8
  • 34
  • Thank you so much for helping me I was trying to solve this issue from 2 days. You have resolved my problem in 1 minute. Thanks again :) – Ahmad dar Jun 01 '14 at 12:29