Multiple cocos2dx Sprite creation methods, cocos2dxsprite
1. Create a file
Sprite *bg = Sprite::create("backGround.jpg");
2. Create an image in a region
1 SpriteFrame *frame = SpriteFrame::create("pean.jpg", Rect(0, 0, 300, 300));2 Sprite *pean = Sprite::createWithSpriteFrame(frame);3 bg->addChild(pean);
3. Create a texture using texture2d (less)
1 Image *image = new Image();2 image->initWithImageFile("pean.jpg");3 4 Texture2D *texture = new Texture2D();5 texture->initWithImage(image);6 7 Sprite *pean = Sprite::createWithTexture(texture);8 bg->addChild(pean);
4. Use SpriteFrameCache (the plist file is created through 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);