Search code examples
scalecocos2d-x

COCOS2D-X: scale sprite


I want to set scale for a sprite by height of original image. And then the width of that sprite will follow by original ratio of that image. How can i do that. Thank for all your help.


Solution

  • CCSprite has a member function

    virtual void setScale(float scale)      
    

    Reference:setScale

    Just create a sprite, and call this function.

    CCSprite* bg = CCSprite::create("background.png");
    this->addChild(bg,0);
    bg->setScale(2.0);
    

    bg sprite will be twice bigger than the origin one.