COCOS2D-X: scale sprite

青春壹個敷衍的年華 提交于 2019-12-02 04:41:48

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!