不使用 XNA 或其他第三方库的 2d Sprite 动画 [英] 2d Sprite Animations without using XNA or other third-party libraries

查看:16
本文介绍了不使用 XNA 或其他第三方库的 2d Sprite 动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的游戏,类似于可以使用 RPG Maker 创建的游戏.我目前主要寻找的是一个教程,它可以指导我如何在不使用 XNA 或任何其他特定库的情况下完成它.

最理想的是分步教程或易于理解的良好示例.

我的目标是自己完成,并了解整个过程如何处理彼此相关的动画元素.

过去我已经使用一个简单的教程构建了一个简单的蛇游戏,但其中没有运动动画,这是我接下来想要学习的主要内容.

到目前为止我发现的所有教程都使用第三方库.我确实遇到过 是一种格式,您可以在其中包含一系列简单的图像帧,它们旨在作为一个系列显示(因此会产生动画的错觉).如果您要使用这种格式创建精灵,您可以使用类似于在此 SO 中找到的代码讨论,其中提供了一些示例代码,用于说明如何使用 C# 为动画 .gif 设置动画并控制其开始/停止.

或者,如果你想使用一个精灵文件(就像我上面提到的那个),你可以使用类似于 这个 CodeProject 代码,它侧重于 GDI 与 Windows 环境的交互,以便提取精灵的一部分并将其绘制到目标画布上.通过每 x 毫秒重绘(如上所述),这可以提供相同的效果.

需要牢记的几点:

您需要处理精灵中的透明度(例如,上面的马里奥精灵具有透明背景) - 以便您的游戏环境背景显示出来.如果使用 GDI - 这一切都与您如何调用绘画方法有关.如果使用动画 .gif - 使用的方法取决于您在窗口上的显示方式.

有关其他资源/示例/参考资料,请查看以下资源:

对于 Sprite 开发:

I want to create a simple game, similar to what can be created with RPG Maker. What I am primarily looking for at the moment is a tutorial which can guide me on how to accomplish it without using XNA or any other specific library.

The ideal would be a step-by-step tutorial or a good, easy-to-understand example.

My goal is to do it on my own, and come to an understanding of how the overall process works with regards to animation elements relating to one another.

I've already built a simple snake game in the past using a simple tutorial, but there was no movement animation in it and that's the primary thing I'm wanting to learn next.

Edit:

All of the tutorials I have found so far use third-party libraries. I did come across this link, but I'm looking for something which doesn't include XNA.

解决方案

There are a number of ways to approach the topic you're describing. I'm going to give a bit of an overview, and then hopefully provide some resources which can give you examples to get you started.

Essentially, sprite-based animations revolve around having a series of similar images which, when displayed sequentially, create the appearance of motion, similar to a flip-book.

The trick is to understand when your sprite is moving (and therefore should be animated) - and when it is standing still (and therefore should not be animated). In other words - assuming that your game's character is only supposed to move while you hold , , or , you need to detect when one of those keys starts and stops being pressed, so that you can start/stop your animation accordingly.

Imagine that for simplicity, you only have 2 sprites. The first (left, below) represents your character standing still, and the second represents your character mid-step (right, below):

When the button is not pressed, you simply continually display the first image. When the button is pressed, you toggle between the two every x milliseconds (depending on how fast you want the animation to appear).

An animated .gif is one format in which you can contain a series of simple image frames, which are intended to be displayed as a series (and therefore create the illusion of animation). If you were to create your sprites using this format, you could use code similar to that found in this SO discussion, which provides some example code for how to use C# to animate an animated .gif and control its start/stop.

Alternatively, if you wanted to use a sprite file (like the one I included above), you could use something similar to this CodeProject code, which focuses on GDI interaction with the Windows environment in order to extract and paint a portion of the sprite onto a target canvas. By repainting every x milliseconds (as mentioned above), this can provide the same effect.

A few things to keep in mind:

You'll need to handle transparency in your sprites (the Mario sprite above, as an example, has a transparent background) - so that the background of your game environment shows through. If using GDI - this all has to do with how you call the painting methods. If using an animated .gif - the method to use depends on how you display it on your window.

For some additional resources / examples / references, check out the following resources:

And for Sprite development:

这篇关于不使用 XNA 或其他第三方库的 2d Sprite 动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆