1. Create from File
Sprite *BG = sprite::create ("background.jpg");
2. Create from an area of the picture
1 Spriteframe *frame = spriteframe::create ("pean.jpg", Rect (00300 )); 2 Sprite *pean = sprite::createwithspriteframe (frame); 3 Bg->addchild (Pean);
3. Create by Texture2d texture (less in this way)
1 New Image (); 2 Image->initwithimagefile ("pean.jpg"); 3 4 New texture2d (); 5 Texture->initwithimage (image); 6 7 Sprite *pean = sprite::createwithtexture (texture); 8 Bg->addchild (Pean);
4. Created with Spriteframecache (plist file via Zwoptex)
1 spriteframecache::getinstance ()->addspriteframeswithfile ("person.plist" ); 2 3 spriteframe *frame = spriteframecache::getinstance ()->getspriteframebyname (" Navigationbar_back.png"); 4 5 Sprite *pean = sprite::createwithspriteframe (frame); 6 Bg->addchild (pean);
Multiple ways to create a COCOS2DX sprite