Search code examples
cocos2d-x

How to scale a sprite(CCSprite) in cocos2d-x(android) ?


I am trying to scale a background sprite (which uses a larger size image resource) to a lower size but unable to do that.

I am doing it as follows :

CCSprite *splashSprite =CCSprite::spriteWithFile("splashscreen.jpg");
 splashSprite->setPosition(ccp(240, 150));
 splashSprite->setScale(0.5f);

But sprite remains its original size. No change. Please help.


Solution

  • you can do this way . it works

    CCSprite* splashSprite= CCSprite::create("splashscreen.png");
    splashSprite->setPosition(ccp(240, 150));
    splashSprite->setScale(0.5f);
    this->addChild(splashSprite, 0);