.animationImages API Cocos 2D?

发布于 2024-12-12 09:02:09 字数 206 浏览 3 评论 0原文

我希望做一些类似于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ˇ宁静的妩媚 2024-12-19 09:02:09
    //initialize anitmation
    CCAnimation *anime= [[CCAnimation alloc] initWithName:@"anime" delay:4.0];

    for(int i = 1; i <= 5; i++){
            [anime addFrameWithFilename:[NSString  stringWithFormat:@"frame%d.png", i]];
    }

    id animeAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:anime]];

   [self runAction:animeAction];

它需要 5 张图像并在 4.0 周期内对它们进行动画处理。

- - - 编辑 - - -
以下是如何使用新的 Cocos2d Api 1.0.1 做到这一点:

    //initialize anitmation
    CCAnimation *anime= [CCAnimation animation];
    anime.delay = 4.0;

    for(int i = 1; i <= 5; i++){
            [anime addFrameWithFilename:[NSString  stringWithFormat:@"frame%d.png", i]];
    }

    id animeAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:anime]];

   [self runAction:animeAction];
    //initialize anitmation
    CCAnimation *anime= [[CCAnimation alloc] initWithName:@"anime" delay:4.0];

    for(int i = 1; i <= 5; i++){
            [anime addFrameWithFilename:[NSString  stringWithFormat:@"frame%d.png", i]];
    }

    id animeAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:anime]];

   [self runAction:animeAction];

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 :

    //initialize anitmation
    CCAnimation *anime= [CCAnimation animation];
    anime.delay = 4.0;

    for(int i = 1; i <= 5; i++){
            [anime addFrameWithFilename:[NSString  stringWithFormat:@"frame%d.png", i]];
    }

    id animeAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:anime]];

   [self runAction:animeAction];
恋竹姑娘 2024-12-19 09:02:09

使用 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.

站稳脚跟 2024-12-19 09:02:09

查看 CCAnimationCCAnimateCCSpriteFrame 类。

CCSpriteFrame 表示一块较大的纹理,称为精灵表。您可以将五张图像放入一张纸中。

CCAnimation 允许您从一系列此类帧创建动画,并设置动画运行的速度

CCAnimate 允许您将该动画作为动作运行

[node runAction:[CCAnimate actionWithAnimation:animationInstance restoreOriginal:NO]];

链接

CCSpriteFrame 类参考

CCAnimation 类参考

CCAnimate 类参考

Zwoptex 用于创建精灵表 - 也有免费的 Flash 版本

Have a look at the CCAnimation, CCAnimate and CCSpriteFrame 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:

[node runAction:[CCAnimate actionWithAnimation:animationInstance restoreOriginal:NO]];

.

Links

CCSpriteFrame class reference

CCAnimation class reference

CCAnimate class reference

Zwoptex for creating sprite sheets - There is a free flash version around too

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文