Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

use setScale function of CCSprite e.g -

CCSprite *Sprite   =   CCSprite::create(WHEEL_SPRITE);
Sprite->setScale(DIRECTOR_VISIBLE_HEIGHT*0.65/Sprite->getContentSize().height);
Sprite->setPosition(ccp(DIRECTOR_VISIBLE_WIDTH/2, DIRECTOR_VISIBLE_HEIGHT/2));
this->addChild(Sprite);

You can scale by width or height only with: sprite->setScaleX() and sprite->setScaleY()

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top