欢迎使用CSDN-markdown编辑器
2016-04-12 11:14
309 查看
1、创建方法一
2、方法二
这里get instance()被提示为过时函数,可能是编译器抽风
3、方法三
4、中途修改sprite的图片
initWithFile
initWithSpriteFrameName
setTexture
注意:被修改的精灵尽可能是一个本身有图片的精灵。否则出错的概率很大,尤其使用box2d引擎的时候,引擎将失效。一个很懒的解决办法是,每次创建精灵都默认设置一张图片。方法有点笨,但是简单使用。
4、精灵播放帧动画
说到帧动画,不得不提一下骨骼动画,感觉骨骼动画真的很酷,但是目前我的水平来讲,也只能老老实实用帧动画咯。
Sprite *sp = Sprite::create();
2、方法二
Texture2D *textture = TextureCache::getInstance()->addImage("kaishi.png"); Sprite *sp = Sprite::createWithTexture(textture);
这里get instance()被提示为过时函数,可能是编译器抽风
3、方法三
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("dqqIMG.plist"); auto spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("slingshot1.png"); slingshotSprite = Sprite::createWithSpriteFrame(spriteFrame);
4、中途修改sprite的图片
initWithFile
initWithSpriteFrameName
setTexture
注意:被修改的精灵尽可能是一个本身有图片的精灵。否则出错的概率很大,尤其使用box2d引擎的时候,引擎将失效。一个很懒的解决办法是,每次创建精灵都默认设置一张图片。方法有点笨,但是简单使用。
4、精灵播放帧动画
说到帧动画,不得不提一下骨骼动画,感觉骨骼动画真的很酷,但是目前我的水平来讲,也只能老老实实用帧动画咯。
cocos2d::Vector<cocos2d::SpriteFrame*>slingshotFrames; auto spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("slingshot0.png"); slingshotFrames.pushBack(spriteFrame); auto spriteFrame1 = SpriteFrameCache::getInstance()->getSpriteFrameByName("slingshot1.png"); slingshotFrames.pushBack(spriteFrame1); auto spriteFrame2 = SpriteFrameCache::getInstance()->getSpriteFrameByName("slingshot2.png"); slingshotFrames.pushBack(spriteFrame2); auto spriteFrame3 = SpriteFrameCache::getInstance()->getSpriteFrameByName("slingshot1.png"); slingshotFrames.pushBack(spriteFrame3) Animation *anim = Animation::createWithSpriteFrames(slingshotFrames,1.0f/20.0f); slingshotSprite->runAction(Animate::create(anim));
相关文章推荐
- STL Algorithms in Action
- Scalaz(38)- Free :Coproduct-Monadic语句组合
- WindowsCE project missing Microsoft.CompactFramework.CSharp.targets in Visual Studio 2008
- STL sort 的用法
- 高性能MySQL笔记-第5章Indexing for High Performance-003索引的作用
- 元组的cmp()内建函数
- android大文件上传断点续传
- dequeueReusableCellWithIdentifier: 与dequeueReusableCellWithIdentifier: forIndexPath:的区别
- ios运行内存
- Android编程实现可滑动的开关效果(附demo源码下载)
- Springcache 应用配置说明
- BZOJ 3576: [Hnoi2014]江南乐
- 奇虎360 QConf 配置管理工具安装使用文档
- 网络备忘之参考资料
- oracle EM中accessibility mode为disable解决方案
- Maven编译error LifecyclePhaseNotFoundException
- iPhone键盘自定义及通知
- 如何真正的从细节上节省网站用户的时间
- day01
- git pull --rebase丢文件丢失修改了怎么办