Cocos2d-X CCSprite set texture (image) Size

Source: Internet
Author: User

Multiple parties are very powerful and can meet the needs of many different time points. When the image size is not the required size, you should use scaling to meet your needs. The scaling factor = the required size/original image size;

As follows:

; CCSize size = CCDirector: sharedDirector ()-> getWinSize (); CCSprite * CCSprite: create (". /Images/menu/ingamepig.png "); //, CCRectMake (800,480,); CC_BREAK_IF (! BackGround); float scalX = size. width/backGround-> getContentSize (). width; // set the scale factor float scalY = size in the X axis direction. height/backGround-> getContentSize (). height; // set the backGround-> setScaleX (scalX); backGround-> setScaleY (scalY); backGround-> setPosition (ccp (size. width/2, size. height/2); this-> addChild (backGround, 0, 0 );

Original Image Size

650) this. width = 650; "src ="/e/u/themes/default/images/spacer.gif "word_img =" file: // C: \ Users \ john \ AppData \ Roaming \ Tencent \ Users \ 1617176084 \ QQ \ WinTemp \ RichOle \ 4TW ~ S6%xnk'qt%uz%q9v4np.jpg "style =" url (/e/u/lang/zh-cn/images/localimage.png) no-repeat center; border: 1px solid # ddd "/> 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2053045143-0.png "title =" .png "/>

Scaled Image


650) this. width = 650; "src =" http://img1.51cto.com/attachment/201308/115203769.png "title =" scaled image .png "/>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.