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);
|
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。