如何为 Android 创建一个简单的 2D 游戏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23274049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:58:17  来源:igfitidea点击:

How to create a simple 2D game for Android?

androidgame-enginegame-physics

提问by Hamed Momeni

I'm a complete newbie when it comes to game development and I need someone to point me to the right direction.
For the sake of clarity please consider the following animation. simple zombie game animation

在游戏开发方面,我是一个完全的新手,我需要有人为我指明正确的方向。
为了清楚起见,请考虑以下动画。 简单的僵尸游戏动画

Basically I need to know how to emulate the above animation as an Android game but I don't know the steps necessary to do as such. My questions can be summarized as follow:

基本上我需要知道如何将上述动画模拟为 Android 游戏,但我不知道这样做所需的步骤。我的问题可以总结如下:

  • Do I need to use a Game Engine for such simple games?
  • Or it can be done without the use of any particular framework?
  • Do I need to use an animation application such as Adobe Flash?
  • What are the necessary steps to make this kind of game?
  • 对于这么简单的游戏,我需要使用游戏引擎吗?
  • 或者它可以在不使用任何特定框架的情况下完成?
  • 我是否需要使用 Adob​​e Flash 等动画应用程序?
  • 制作这种游戏的必要步骤是什么?

采纳答案by free3dom

Using a game engine or not is a preference. It will depend on what exactly you are after. If you want to learn about the underlying concepts of rendering, collision detection, etc, then writing these yourself is perfectly acceptable, and a lot of fun. On the other hand, if you just want to get the game done without having to worry about the details then an engine is definitely the way to go.

是否使用游戏引擎是一个偏好。这将取决于你到底想要什么。如果你想了解渲染、碰撞检测等的底层概念,那么自己写这些是完全可以接受的,而且很有趣。另一方面,如果您只想完成游戏而不必担心细节,那么引擎绝对是您的最佳选择。

Game engines range from very basic wrappers (which usually provides easier functions that take care of low level tasks) to highly complex abstractions in which the actual game development no longer resembles any specific platform - they also sometimes allow you to create the game once and deploy it to various platforms without any changes.

游戏引擎的范围从非常基本的包装器(通常提供处理低级任务的更简单的功能)到高度复杂的抽象,其中实际游戏开发不再类似于任何特定平台 - 它们有时还允许您创建游戏一次并部署它没有任何变化地适用于各种平台。

To implement a game based on that animation you might use the following:

要基于该动画实现游戏,您可以使用以下内容:

  • For each non-player character create a series of consecutive "frames" which when cycled gives the illusion of movement. These can be created in any graphics application (preferably in a texture map/atlas).
  • For the player character, you will need an animated sequence for each "move", such as kick, punch, etc. Then play the correct sequence when the player triggers some action (ex. play the kicksequence when the player pushes a kick button).
  • Each character should have a bounding box (i.e. a rectangle that defines the size and position of the character). The player character should probably have a different sized box based on the type of attack (i.e. the box for the kickaction would extend farther to the right than the box for the punchaction.
  • Randomly spawn characters at the right of the screen and move them at some speed (based on type?) towards the player. During each iteration, test for collisions between the player and each non-player's bounding boxes. If a collision is found, check if the player is kicking or punching and kill the character that was hit, if the player is not attacking maybe damage him/her.
  • 为每个非玩家角色创建一系列连续的“帧”,循环时会产生运动的错觉。这些可以在任何图形应用程序中创建(最好在纹理贴图/图集中)。
  • 对于玩家角色,您将需要一个动画序列的每个“动作”,比如kickpunch等等。然后当玩家触发一些行动中发挥了正确的序列(例如,播放kick顺序当玩家按下一个按钮踢)。
  • 每个字符都应该有一个边界框(即定义字符大小和位置的矩形)。根据攻击的类型,玩家角色可能应该有一个不同大小的盒子(即kick动作的盒子会比punch动作的盒子向右延伸得更远。
  • 在屏幕右侧随机生成角色,并以一定速度(基于类型?)向玩家移动它们。在每次迭代期间,测试玩家和每个非玩家的边界框之间的碰撞。如果发现碰撞,检查玩家是否在踢或出拳并杀死被击中的角色,如果玩家没有攻击可能会伤害他/她。

That is a very basic description of your problem and should give you enough ideas to research in order to implement a basic version :)

这是对你的问题的一个非常基本的描述,应该给你足够的想法来研究以实现一个基本版本:)

Some game engines you might want to look into:

您可能想要研究的一些游戏引擎:

If you are interested in learning about making android games specifically, have a look at this book:

如果你有兴趣学习专门制作安卓游戏,看看这本书:

回答by atlassium

There are many game engines out there that can help you can get the job done.

有许多游戏引擎可以帮助您完成工作。

Here is a linkfor all the mobile game engines out there.

这是所有移动游戏引擎的链接



Android 2D Game Engines

Android 2D 游戏引擎

Cocos2D-x

Cocos2D-x

Language: C++

语言:C++

Orientation: 2D

方向:2D

Difficulty: Intermediate

难度:中级



Corona SDK

电晕SDK

Language: Lua

语言: Lua

Orientation: 2D/3D

方向:2D/3D

Difficulty: Intermediate

难度:中级



EDGELIB

EDGELIB

Language: C++

语言:C++

Orientation: 2D

方向:2D

Difficulty: Intermediate

难度:中级



GameMaker

游戏制作者

Language: None (Graphical)

语言:无(图形)

Orientation: 2D

方向:2D

Difficulty: Easy

难度:容易



GameSalad

游戏沙拉

Language: None (Graphical)

语言:无(图形)

Orientation: 2D

方向:2D

Difficulty: Easy

难度:容易



HaxeFlixel

HaxeFlixel

Language: Haxe

语言:哈克斯

Orientation: 2D

方向:2D

Difficulty: Intermediate

难度:中级



libGDX

库GDX

Language: Java

语言:Java

Orientation: 2D/3D

方向:2D/3D

Difficulty: Intermediate

难度:中级



Marmalade

果酱

Language: C++

语言:C++

Orientation: 2D/3D

方向:2D/3D

Difficulty: Intermediate

难度:中级



Stencyl

斯泰西尔

Language: ActionScript (optional), Objective-C (optional)

语言:ActionScript(可选)、Objective-C(可选)

Orientation: 2D

方向:2D

Difficulty: Intermediate

难度:中级



Unity3D

Unity3D

Language: JavaScript (UnityScript actually), C# (Mono)

语言:JavaScript(实际上是UnityScript),C#(Mono)

Orientation: 2D/3D

方向:2D/3D

Difficulty: Intermediate

难度:中级

回答by josedlujan

I answer in the order you asked

我按你问的顺序回答

  1. It is recommended to always use an engine, because they make the job easier, that's what they are for.

  2. You can do certain animations and movements without a framework, but it actually becomes more complex with the code and logic.

  3. Adobe Flash is useless on android. Most android devices do not run Flash without the user doing some things to get it.

  4. The steps that I recommend are

    • research some engines
    • review some frameworks
    • select and engine depending on the logic of your game
  5. Some engines are available for adventure games, puzzles, and other RPGs. Depending on your need go for one.

  1. 建议始终使用引擎,因为它们使工作更轻松,这就是它们的用途。

  2. 你可以在没有框架的情况下做某些动画和动作,但实际上随着代码和逻辑变得更加复杂。

  3. Adobe Flash 在安卓上没用。大多数 android 设备都不会运行 Flash,除非用户做一些事情来获取它。

  4. 我推荐的步骤是

    • 研究一些引擎
    • 回顾一些框架
    • 根据您的游戏逻辑选择和引擎
  5. 一些引擎可用于冒险游戏、拼图和其他 RPG。根据您的需要选择一个。

A few simple programs:

几个简单的程序:

  • App Game Kit
  • Cocos2d for Android
  • Corona SDK
  • GameMaker
  • Stencyl
  • 应用游戏套件
  • 安卓版 Cocos2d
  • 电晕SDK
  • 游戏制作者
  • 斯泰西尔

You can start with these. Unity is the best engine, but the most complicated too.

你可以从这些开始。Unity 是最好的引擎,但也是最复杂的。

回答by FRR

I asked myself this question for about 10 years before finding a good answer, in my opinion, all gaming frameworks for android are still not quite mature or are a bit difficult to implement. I would recommend you used this. You'll be able to run your game in all devices out there (not only android). It's quite easy to learn if know the basics.

我问了自己这个问题大约 10 年才找到一个好的答案,在我看来,所有适用于 android 的游戏框架都还不是很成熟,或者实现起来有点困难。我建议你使用这个。你将能够在所有设备上运行你的游戏(不仅仅是安卓)。如果了解基础知识,学习起来很容易。

Here's a great Tutorialto get you started!

这是一个很棒的教程,可以帮助您入门!

I made a game, using adobe's technology, you can check it out here.

我制作了一个游戏,使用 adobe 的技术,你可以在这里查看