Skip to content

基本游戏制作概念:开始使用 GDevelop 需要了解的内容

GDevelop 的基本概念很简单。阅读以下信息以开始使用该软件。如果您尚未安装 GDevelop,请在此处下载最新版本

在屏幕上显示东西:对象

在屏幕上显示的所有内容都称为"对象"。可以使用不同类型的对象来显示屏幕上的不同游戏元素。例如,大多数游戏图形是"精灵(Sprite)"对象,文本可以用"文本"对象显示,而火或爆炸等特效可以用"粒子发射器(Particle Emitters)"创建。

阅读更多关于对象

对象示例

在世界中定位对象:坐标

GDevelop 屏幕/场景上的对象具有"X"和"Y"坐标。这些坐标对应于_笛卡尔平面_上的水平位置(X 轴)和垂直位置(Y 轴)。

X 坐标随着向左移动而_减少_,随着向右移动而_增加_。Y 坐标随着向下移动而_增加_,随着向上移动而_减少_。

提示:您的游戏屏幕的左上角坐标为 X = 0,Y = 0,但如果相机移动,这将会改变。

坐标示例

角度

为了移动或旋转对象,您需要指定所需的角度(度)。下面的插图演示了 GDevelop 如何理解旋转角度:

提示:角度也可以是负数。例如,-90 度等于 270 度。

角度示例

位置和角度示例

下面的视频显示了 GDevelop 中这两个概念。通过修改 X 和 Y 值来改变飞船的位置,然后通过改变对象的角度来旋转飞船。

位置和角度示例

事件

事件用于创建游戏的逻辑。它们由条件和动作组成。条件可以被视为"如果"语句,动作可以被视为"然后"语句。"如果"条件为真/满足,则"然后"动作将发生。大多数条件和动作涉及对象:

  • 条件对对象运行测试
  • 动作影响符合条件的对象。它们可以改变对象的位置、外观等...

没有任何条件的事件将始终执行动作。在下面的视频中,飞船对象将以旋转速度执行动作。

无条件事件示例

如果向事件添加条件,那么只有当条件为真时,才会执行动作。

在本示例中,添加了一个光标/触摸在飞船上的条件。现在旋转飞船动作只会在鼠标光标位于飞船对象上时发生。

带条件事件示例

阅读更多关于事件

对象如何被选择

如果一个事件没有条件,那么动作将应用于动作中列出的所有对象。例如,此事件没有条件,因此将删除所有称为"飞船"的对象。

对象选择示例

一旦添加了涉及对象的条件,所有后续动作将仅影响与先前条件匹配的对象。

以下事件具有一个条件,检查飞船的水平(X)位置。此动作将删除其 X 位置小于(在鼠标光标左侧)的"飞船"对象。

提示:匹配条件的对象列表也被所有子事件使用。

阅读更多关于对象选择

通过鼠标位置删除飞船示例

提示:查看实际操作! 🎮 在线打开此示例

对象选择示例

事件顺序

事件的顺序非常重要

事件从上到下进行处理。因此,顶部的事件首先被执行。以下示例等价:

事件顺序示例 1

事件顺序示例 2

  • 在顶部示例中,第一个事件在基本图层的坐标 X:100,Y:200(100;200)处创建一个"飞船"对象。然后下一个事件立即删除该创建的飞船。这对事件不会在屏幕上显示飞船,因为飞船在创建后立即被删除。
  • 在底部示例中,第一个事件从场景/屏幕中删除所有"飞船"对象。然后在基本图层的坐标 X:100,Y:200(100;200)处创建一个"飞船"。这对事件在屏幕上显示一艘飞船。(幕后,飞船正在每一帧被删除和重建,这不是您真实游戏中想要做的事情。)

提示:事件每秒处理约 60 次。

每次事件迭代称为游戏循环

行为:对象的游戏逻辑 ---------------------------------Behaviors enhance an object with some pre-defined logic. They can be used to automate simple tasks, but they also have the power to perform much more advanced tasks. For example:

  • A behavior can be used to automatically remove an object from the game when it goes out of the screen (limiting the game memory usage).
  • Another behavior can be used to move objects on the screen with the keyboard arrows.
  • Yet another behavior can be used to allow the object to be dragged on screen with the mouse or by touching the object.
  • The Physics behavior is an example of an advanced behavior which make your objects move in a realistic way, following the laws of physics.

Behaviors will often come with their own variables that can be changed to customize the task it performs, but they can also be manipulated using events that are specific to that behavior.

The wiki page associated with behaviors can be found here.

Tip

You can create custom behaviors for your objects. We recommend this as your game grows. It allows you to put logic about what your objects are doing in the custom behaviors, rather than bloating the scene's events sheet. You read more in this article.

Move objects with Forces

Moving objects can be achieved with forces. Forces are used to "push" objects.

You can specify:

  • The speed of movement on both the X (horizontal) and Y (vertical) axis, in pixels per second
  • The angle to move towards and the speed, in pixels per second
  • An instant force will only move the object for one frame
  • A permanent force will move the object every frame until it is stopped

Example

Below is an example that moves a ship object back and forth between the left and right sides of the screen.

To move the ship left, add a permanent force with an angle of 180° (left) and a length (speed) of 50 pixels per second. This force is applied on every frame when the X position of the ship is greater than 600.

To move the ship to the right, add a permanent force with a speed of 50 pixels per second on the X-axis and 0 for the Y-axis. This force is applied on every frame when the X position of the ship is less than 200.

Note

This example applies permanent forces over multiple frames, which causes the ship to accelerate and decelerate when changing directions.

Other ways to move objects

Some "behaviors", like the Physics engine or Pathfinding, may move the objects by themselves. In this case, it is better not to use the built-in forces system and instead rely only on actions provided by these behaviors.

Tip

See it in action! 🎮 Open this example online.

Note

These other ways of moving objects are explained in this how-to page.

Variables: Storing information

Variables are used to store data in the format of a number or text. This data can represent almost anything in your game. For example, it could be used to record the number of lives remaining, a player's name, a high score, the number of bullets left, or the number of enemies killed. Variables are useful because they allow you to set the value in one place and then read that value in multiple places in your game.

Tip

Conditions are used to check the value of a variable.

Actions are used to change the value of a variable.

Where are variables stored? (variable "scope")

The scope of a variable determines the place a variable can be accessed. In GDevelop, there are three variable scopes are available:

  • Global variables are accessible from all the game scenes. For instance, they can be used to store the player's score across different levels/scenes.
  • Scene variables are only accessible from the scene they are created in. They can be used for data that only concerns one scene. A Scene variable would be able to access the time remaining to complete the level/scene.
  • Object variables only concern one object. For example, a hero can have a "Health" or "Ammo" variable.

The wiki page associated with variables can be found here.

To further expand on how variables can be used in a game, see expressions.

TimeDelta: "Time elapsed" since the previous frame

GDevelop processes events and redraws the screen (called a "frame") around 60 times per second. The exact number of frames per second depends on the computer resources and the demands of the game. A slow computer might only render 25 frames per second, while a fast computer could render 60 frames per second. In order for a game to feel the same on every device, it is important to take into account the time elapsed between frames.

This can be accomplished by using //TimeDelta()//, which returns the time in seconds since the last frame.

For example, don't do this:

But do this instead:

The first event is adding 20 to the variable on every frame. This means that the rate of increase of the variable may not be the same from computer to computer. We need to compensate for this variation in frame rates.

第二个事件是正确且可靠:数字300乘以TimeDelta()。因此,变量将以相同的速率增加在所有计算机上。因为_TimeDelta()返回以秒为单位的时间,它可以精确地量化变量随时间的变化量。在我们的情况下,变量将以300单位/秒增长。因此,我们可以预测生命值将在10秒内增加3000单位,无论在此期间处理了多少帧。**经验法则:**当您希望持续将改变应用于值时使用_TimeDelta()。如果您的操作仅运行一次(例如,在碰撞期间然后删除对象),则无需使用_TimeDelta()_。危险您不需要在期望以“单位每秒”为单位的值时使用_TimeDelta()(例如,使用力移动对象)。在这些情况下,GDevelop会自动考虑帧速率的差异。这几乎就是您需要了解的全部。➡️ 您可以继续阅读**教程**,了解更多关于使用GDevelop创建真正游戏的知识!