你如何在Cocos2d中制作动画?

时间:2020-12-05 20:55:10

I am trying to animate a sprite. The cocos2d website makes it look so easy but everytime I try it I get errors. I managed to download some code to get it working but one sprite animation takes 6 files. I have a character that needs to walk right and left, jump, climb, and fall. That means I am looking at 35 files. can't it be streamlined a bit? It just seems way harder than it should be.

我正在尝试为精灵制作动画。 cocos2d网站让它看起来如此简单,但每次我尝试它都会出错。我设法下载了一些代码以使其工作,但一个精灵动画需要6个文件。我有一个需要左右走,跳,爬,跌的角色。这意味着我正在查看35个文件。难道不能精简一点吗?它似乎比它应该更难。

Thanks, Josh

4 个解决方案

#1


Cocos is great. You just need to spend time with the demo project, hang out on the message board, and keep at it.

科科斯很棒。你只需要花时间在演示项目上,在留言板上闲逛,并坚持下去。

You animate a sprite like this:

你动画像这样的精灵:

id action = [Sequence actions:
             [ScaleTo actionWithDuration:.3 scale:0.7f],
             [ScaleTo actionWithDuration:.3 scale:1.0f],
             nil];

[[self getByTag:FOO] do:action];

This causes the sprite with the tag FOO to scale down to 70 percent in .3 seconds, then back up to 100 percent in .3 seconds.

这会导致带有标签FOO的精灵在0.3秒内缩小到70%,然后在0.3秒内恢复到100%。

Much more complex animations are possible, just get the basics down and the world will be ya oyster, at least as far as making stuff fly around on the screen, that is.

更复杂的动画是可能的,只需要掌握基础知识,世界将是牡蛎,至少就是让东西在屏幕上飞来飞去,就是这样。

#2


    UIImageView* headBandAnimation = [[UIImageView alloc] initWithFrame:CGRectMake(25, 205, 100, 50)];
    headBandAnimation.animationImages = [NSArray arrayWithObjects:    
                                    [UIImage imageNamed:@"band1.png"],
                                    [UIImage imageNamed:@"band2.png"],
                                    [UIImage imageNamed:@"band3.png"],
                                    [UIImage imageNamed:@"band4.png"], nil];
    headBandAnimation.animationDuration = 0.5;
    headBandAnimation.animationRepeatCount = 0;
    [headBandAnimation startAnimating];
    [self.view addSubview:headBandAnimation];

is how to do animation without cocos2d if you wish to go this route.

如果你想走这条路,怎么做没有cocos2d的动画。

#3


Cocoa With Love have a short-series on writing a came using CoreAnimation, perhaps it might be of use?

Cocoa With Love有一篇关于使用CoreAnimation写一篇文章的短篇小说,也许它可能有用吗?

Cocoa does take a lot of getting used to, and does seem really overly convoluted, but when you compared it to.. well, most other GUI toolkits I've used, it suddenly seems very elegant and simple. The problem with the example code, and most tutorials (including the one I linked to, albeit to a slightly lesser degree) is they only show you the finished application - it doesn't show the increments. There's no "I have a empty canvas", then "I worked out how to draw a circle", then "I've animated the circle".

Cocoa确实需要很多习惯,并且看起来确实过于复杂,但是当你将它与...相比时,我使用过的大多数其他GUI工具包,突然看起来非常优雅和简单。示例代码的问题,以及大多数教程(包括我链接到的教程,虽然程度略低)是它们只显示完成的应用程序 - 它不显示增量。没有“我有一个空的画布”,然后“我弄清楚如何绘制一个圆圈”,然后“我给圆圈制作了动画”。

Try making a new application, look through the example code/IB project/tutorials/documentation for the bit that initialises the canvas-thing. Then look for the code that adds a simple shape. Then look for the code to animate the code (Genericrich answer, for example)

尝试创建一个新的应用程序,查看示例代码/ IB项目/教程/文档,了解初始化canvas-thing的位。然后查找添加简单形状的代码。然后查找代码以设置代码动画(例如,Genericrich答案)

#4


I know this thread is much older, but for future reference this is the article which seems best fit for this question.

我知道这个帖子比较老了,但是为了将来参考,这篇文章似乎最适合这个问题。

It involves TexturePacker tool which generates a PLIST and a PNG that fulfill our needs.

它涉及TexturePacker工具,它生成满足我们需求的PLIST和PNG。

#1


Cocos is great. You just need to spend time with the demo project, hang out on the message board, and keep at it.

科科斯很棒。你只需要花时间在演示项目上,在留言板上闲逛,并坚持下去。

You animate a sprite like this:

你动画像这样的精灵:

id action = [Sequence actions:
             [ScaleTo actionWithDuration:.3 scale:0.7f],
             [ScaleTo actionWithDuration:.3 scale:1.0f],
             nil];

[[self getByTag:FOO] do:action];

This causes the sprite with the tag FOO to scale down to 70 percent in .3 seconds, then back up to 100 percent in .3 seconds.

这会导致带有标签FOO的精灵在0.3秒内缩小到70%,然后在0.3秒内恢复到100%。

Much more complex animations are possible, just get the basics down and the world will be ya oyster, at least as far as making stuff fly around on the screen, that is.

更复杂的动画是可能的,只需要掌握基础知识,世界将是牡蛎,至少就是让东西在屏幕上飞来飞去,就是这样。

#2


    UIImageView* headBandAnimation = [[UIImageView alloc] initWithFrame:CGRectMake(25, 205, 100, 50)];
    headBandAnimation.animationImages = [NSArray arrayWithObjects:    
                                    [UIImage imageNamed:@"band1.png"],
                                    [UIImage imageNamed:@"band2.png"],
                                    [UIImage imageNamed:@"band3.png"],
                                    [UIImage imageNamed:@"band4.png"], nil];
    headBandAnimation.animationDuration = 0.5;
    headBandAnimation.animationRepeatCount = 0;
    [headBandAnimation startAnimating];
    [self.view addSubview:headBandAnimation];

is how to do animation without cocos2d if you wish to go this route.

如果你想走这条路,怎么做没有cocos2d的动画。

#3


Cocoa With Love have a short-series on writing a came using CoreAnimation, perhaps it might be of use?

Cocoa With Love有一篇关于使用CoreAnimation写一篇文章的短篇小说,也许它可能有用吗?

Cocoa does take a lot of getting used to, and does seem really overly convoluted, but when you compared it to.. well, most other GUI toolkits I've used, it suddenly seems very elegant and simple. The problem with the example code, and most tutorials (including the one I linked to, albeit to a slightly lesser degree) is they only show you the finished application - it doesn't show the increments. There's no "I have a empty canvas", then "I worked out how to draw a circle", then "I've animated the circle".

Cocoa确实需要很多习惯,并且看起来确实过于复杂,但是当你将它与...相比时,我使用过的大多数其他GUI工具包,突然看起来非常优雅和简单。示例代码的问题,以及大多数教程(包括我链接到的教程,虽然程度略低)是它们只显示完成的应用程序 - 它不显示增量。没有“我有一个空的画布”,然后“我弄清楚如何绘制一个圆圈”,然后“我给圆圈制作了动画”。

Try making a new application, look through the example code/IB project/tutorials/documentation for the bit that initialises the canvas-thing. Then look for the code that adds a simple shape. Then look for the code to animate the code (Genericrich answer, for example)

尝试创建一个新的应用程序,查看示例代码/ IB项目/教程/文档,了解初始化canvas-thing的位。然后查找添加简单形状的代码。然后查找代码以设置代码动画(例如,Genericrich答案)

#4


I know this thread is much older, but for future reference this is the article which seems best fit for this question.

我知道这个帖子比较老了,但是为了将来参考,这篇文章似乎最适合这个问题。

It involves TexturePacker tool which generates a PLIST and a PNG that fulfill our needs.

它涉及TexturePacker工具,它生成满足我们需求的PLIST和PNG。