Objective:
The Sprite class is a Sprite class. Its subclasses have physicssprite and skins.
Physicssprite is the physics engine Elf class, and the skin is an elf class for skeletal animation.
Creating a Sprite Elf Object
There are several ways to create a Sprite object, and the usual functions are as follows:
1) Create a Sprite object, texture and other attributes need to be set after creation
Static sprite* Create ();
2) Specify Image creation wizard
Static sprite* Create (const std::string& filename);
3) Specify the picture and the cropped rectangular area to create the sprite
Static sprite* Create (const std::string& filename, const rect& Rect);
4) Specify texture creation Sprite
Static sprite* createwithtexture (texture2d* texture);
5) Specify the texture and clipping rectangle area to create the sprite, the 3rd parameter specifies whether to rotate the texture, and does not rotate by default
Static sprite* createwithtexture (texture2d* texture, const rect& Rect, bool rotated = false);
6) Create another Sprite object from one Sprite frame object
Static sprite* createwithspriteframe (spriteframe* pspriteframe);
7) Create a Sprite object by specifying the sprite frame name in the frame cache
Static sprite* createwithspriteframename (cosnt std::string & Spriteframename);
code example:
1Auto SPBK = Sprite::create ("Background.png");2 ////position is not set here, the default location is the lower left corner3 //spbk->setposition (Point (origin.x + VISIBLESIZE.WIDTH/2, ORIGIN.Y + visiblesize.height/2));4Spbk->Setanchorpoint (Point::zero);5 This->addchild (SPBK,0);6 7 ////Use a Texture object (texture2d) to create a Sprite object.8 ///Rect (float x, float y, float width, float height);9 //The parameter rect is an area of the Tree1.png picture, the UI coordinate system, the (604,38) coordinate position, the width 302, and the height 295TenAuto Tree1 = Sprite::create ("Tree1.png", Rect (604, -,302,295)); OneTree1->setposition (Point ( $, the)); A This->addchild (Tree1,0); - -texture2d* cache =director::getinstance ()->gettexturecache ( )->addimage ("Tree1.png"); theAuto Tree2 =sprite::create (); -Tree2->settexture (cache); - //The parameter rect is an area of the Tree1.png picture, the UI coordinate system, the (73,72) coordinate position, the width 182, and the height 270 -Tree2->settexturerect (Rect ( the, the,182, the)); +Tree2->setposition (Point ( -, $)); - This->addchild (Tree2,0);
The Texturecache instance can be obtained through the Director::getinstance ()->gettexturecache () function , Texturecache addimage (" Tree1.png ") function to create a texture texture2d object, where Tree1.png is the name of the texture picture.
Cocos2d-x actual combat C + + Volume Learning Notes--5th Chapter Wizard