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