Cocos2d-x Learning Notes (eight) creating a Sprite Object

Source: Internet
Author: User
Tags addchild

The sprite is a sprite, which is actually a two-dimensional picture.

It first directly inherits the node class, therefore, it has the characteristics of nodes, at the same time, it also directly inherits the Textureprotocol class, therefore, it also has the basic characteristics of texture.

Here, it is necessary to popularize the meaning of the texture. Personal understanding, the texture here is actually a two-dimensional image (of course there are three-dimensional texture), it describes the details of the surface of the object, through some kind of projection or mapping way, so that the object itself looks more delicate and real. In other words, a texture is a description of the physical surface details, its existence separates the whole and the details, so you can change the scene of the object by modifying the details. (wordy)

Perhaps just because of the two different characteristics of the sprite inheritance, it derives directly from two classes to materialize these two characteristics, namely: Physicalsprite and skin.

Sprite *BG = Sprite::create ("Background.png"); BG->setanchorpoint (Vec2::zero);//Lower Left     This->addchild (BG,0); Auto Tree1= Sprite::create ("Tree1.png", Rect (604, -,302,295)); Tree1->setposition (VEC2 ( $, the));  This->addchild (Tree1,0); Texture2d*cache = Director::getinstance ()->gettexturecache ()->addimage ("Tree1.png"); Auto Tree2=sprite::create (); Tree2-settexture (cache); Tree2->settexturerect (Rect ( the, the,182, the)); Tree2->setposition (VEC2 ( -, $));  This->addchild (Tree2,0);
View Code

Operation Result:

Figure 1 Texture object creation Sprite Object

Cocos2d-x Learning Notes (eight) creating a Sprite Object

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.