COCOS2D-X:比例精灵 [英] COCOS2D-X: scale sprite

查看:71
本文介绍了COCOS2D-X:比例精灵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过原始图像的高度设置精灵的比例.然后,该精灵的宽度将跟随该图像的原始比例.我怎样才能做到这一点.感谢您的所有帮助.

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具有成员函数

CCSprite has a member function

virtual void setScale(float scale)      

参考: setScale

只需创建一个精灵,然后调用此函数即可.

Just create a sprite, and call this function.

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

bg精灵会比原始精灵大两倍.

bg sprite will be twice bigger than the origin one.

这篇关于COCOS2D-X:比例精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆