.animationImages API Cocos 2D?
我希望做一些类似于 UIImageView 中的 API 的事情,您可以在其中提供 5 个图像,并在一定的时间内 UIImageView 将切换这些图像。我希望在 CCSprite 中执行此操作,但我听说执行此操作的唯一方法是自定义节点框架或类似的方法。
有人知道一种简单的方法来实现这样的事情,我提供了 5 张图像,并且我希望它在 4 秒内循环浏览它们吗?
谢谢!
I am looking to do something similar to the API in UIImageView where you supply say 5 images and through a certain duration the UIImageView will switch through those images. I am looking to do this in a CCSprite but the only ways I hear of doing this is customizing frames of the Node or something like that.
Does someone know an easy way to achieve something like this where I provide say 5 images and I want it to cycle though them in 4 seconds?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它需要 5 张图像并在 4.0 周期内对它们进行动画处理。
- - - 编辑 - - -
以下是如何使用新的 Cocos2d Api 1.0.1 做到这一点:
It takes 5 images and animate them in 4.0 periods.
----- Edit -----
Here is how can you do it with new Cocos2d Api 1.0.1 :
使用 5 个不同的图像创建 5 个精灵。将它们全部放在同一位置。将 4 个精灵设置为不可见(sprite.visible = NO)。
当您想要更改精灵时,只需将另一个精灵设置为可见,并将当前可见的精灵设置为不可见。您还可以应用 CCFadeTo 等操作来淡出一个精灵,同时淡入另一个精灵。
如果您使用淡入淡出,请确保出于性能原因仍设置visible属性。不透明度为 0 的精灵仍会渲染,而不可见的精灵则不会渲染。
Create 5 Sprites with the 5 different images. Place them all at the same position. Set 4 of the sprites to be invisible (sprite.visible = NO).
When you want to change the sprites you only need to set another sprite to visible and the currently visible one to invisible. You can also apply actions like CCFadeTo to fade out one sprite while fading in another.
If you use fading, make sure you still set the visible property for performance reasons. Sprites with opacity of 0 are still rendered, while sprites that are not visible aren't.
查看
CCAnimation
、CCAnimate
和CCSpriteFrame
类。CCSpriteFrame
表示一块较大的纹理,称为精灵表。您可以将五张图像放入一张纸中。CCAnimation
允许您从一系列此类帧创建动画,并设置动画运行的速度。CCAnimate
允许您将该动画作为动作运行:
链接
CCSpriteFrame 类参考
CCAnimation 类参考
CCAnimate 类参考
Zwoptex 用于创建精灵表 - 也有免费的 Flash 版本
Have a look at the
CCAnimation
,CCAnimate
andCCSpriteFrame
classes.The
CCSpriteFrame
represents a piece of a larger texture known as a sprite sheet. You can put your five images into one sheet.CCAnimation
allows you to create an animation out of a sequence of such frames and to set the speed at which the animation runs.And
CCAnimate
allows you to run that animation as an action:.
Links
CCSpriteFrame class reference
CCAnimation class reference
CCAnimate class reference
Zwoptex for creating sprite sheets - There is a free flash version around too