旋转动画

发布于 2024-11-26 07:19:39 字数 452 浏览 3 评论 0原文

我正在编写一个游戏,现在我开始意识到必须提高性能(游戏链接(市场))。

如果你看不出来:这是一场蛇与鸟的游戏。您控制第一只鸟(通过绘制一条让它跟随的路径/使用方向键),一群较小的鸟会排成一行跟随它。这些鸟是有动画的,可以旋转 180° 并进行镜像(取决于它们飞过的位置)。

目前,我只为第一只鸟设置动画,然后将其缩小并将其保存在一个不可见的元素中,该元素在 4 帧后显示(流畅的动画目的),而不是单独为每只鸟设置动画。因此,对于您在屏幕上看到的每只鸟,都有 4 个对象,每个对象都有一个位图。现在我的问题是,我应该制作一个精灵表并减少可能的旋转次数(例如,每 10° 一组精灵)或计算每只鸟的动画,还是保持我的方式?

I'm writing a game and now I'm starting to realize that the performance has to be improved (link to game (market)).

If you can't check it out: It's a snake-like game with birds. You control the first bird (by drawing a path for it to follow / using dpad), and a swarm of smaller birds follows it in line. The birds are animated, and can be rotated by 180° and mirrored (depending where they're flying through).

At the moment I animate the first bird only, then scale it down and save it in an invisible element which is shown 4 frames later (fluid animation purposes), instead of animating each bird individually. So for each bird you see on screen, there are 4 objects with a bitmap each. Now my question is, should I make a spritesheet and reduce the number of possible rotations (say, 1 set of sprites every 10°) or calculate the animation for each bird, or keep it my way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

子栖 2024-12-03 07:19:39

手动制作旋转的精灵表是没有意义的,我只需加载单个精灵表即可。然后为每个角度创建一个位图数组,并在每个角度上旋转和复制基本精灵表。 (您可能需要一组数组来处理动画,或者对精灵表的每个帧进行单独的旋转)这也可以让您稍后轻松地更改您的艺术作品。

类似于:

Bitmap baseFrame;
Bitmap rotatedFrame[]=new Bitmap[360/10];

...

Matrix rotationMatrix=new Matrix();
rotationMatrix.setRotate(n*10);
rotatedFrame[n]=Bitmap.createBitmap(baseFrame,0,0,
                                    baseFrame.getWidth(), baseFrame.getHeight(),
                                    rotationMatrix, false);

旋转图像的宽度和高度可能需要大于基本图像,并且您可能希望将其设置为围绕中心旋转,但您明白了

顺便说一下,

看看您的屏幕截图对于你的游戏,我怀疑绘制背景可能比旋转小鸟有更大的效果。您可能需要分析您的代码以查看绘制每个图像需要多长时间。 ( http://developer.android.com/guide/developing/debugging/ debug-tracing.html )。我会确保您的背景以 RGB_565 格式加载,在软件中渲染时它会快得多。

我发现 Android 中的旋转图像速度快得惊人,能够以良好的帧速率旋转数百个小位图。

There is no point making your rotated sprite sheets by hand, I'd just load in a single sprite sheet. Then make an array of Bitmaps, for each angle, and rotate and copy the base sprite sheets over each. (you may need an array of arrays to handle the animations, or do separate rotates for each frame of the sprite sheet) This also lets you change your art later with ease.

something like:

Bitmap baseFrame;
Bitmap rotatedFrame[]=new Bitmap[360/10];

...

Matrix rotationMatrix=new Matrix();
rotationMatrix.setRotate(n*10);
rotatedFrame[n]=Bitmap.createBitmap(baseFrame,0,0,
                                    baseFrame.getWidth(), baseFrame.getHeight(),
                                    rotationMatrix, false);

The width, and height of the rotated images may need to be larger then to base image, and you may want you set it up to rotate around the centre but you get the idea

By the way,

Having a look at your screenshots of your game I suspect that drawing your background may have a bigger effect then rotating the birds. You may want to profile your code to see how long it's taking to draw each image. ( http://developer.android.com/guide/developing/debugging/debugging-tracing.html ). I'd make sure your background is being loaded in a RGB_565 format, it can be quite a lot faster when rendering in software.

I have found rotating images in android to be surprisingly fast, being able to rotate hundreds of small bitmaps at a good frame rate.

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