cocos2d-x游戏开发5中创建精灵方法:
方法一:直接创建精灵
|
Sprite * sprite = Sprite::create(
"Icon.png"
);
|
|
String* fileName = String::createWithFormat(
"Icon_%d.jpg"
,flag);
Sprite* sprite = Sprite::create(fileName->getCString());
sprite->setPosition(ccp(100,100));
this
->addChild(sprite);
|
|
Sprite * sprite = Sprite::create(
"Icon.png"
,RectMake(0,30,30));
sprite->setPosition(ccp(100,100));
this
->addChild(sprite);
|
适合于plist打包好的文件
|
SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(
"test_icon.plist"
);
Sprite * sprite = Sprite::createWithSpriteFrameName(
"Icon.png"
);
sprite->setPosition(ccp(100,100));
this
->addChild(sprite);
|
适合于做帧动画使用
|
SpriteFrame * frame = SpriteFrame::create(
"Icon.png"
,40,30));
Sprite * sprite = Sprite::createWithSpriteFrame(frame);
sprite->setPosition(ccp(310,150));
addChild(sprite);
|
方法五:利用纹理
适合于需要频繁使用的图片
|
SpriteBatchNode* spriteTexture = SpriteBatchNode::create(
"iocn.png"
);
spriteTexture->setPosition(PointZero);
addChild(spriteTexture);
Sprite* sprite = Sprite::createWithTexture(spriteTexture->getTexture());
sprite->setPosition(ccp(visiblesize.width/2,100));
spriteTexture->addChild(sprite,2);
|