官方的教程,页面在这里:https://www.yoyogames.com/zh-CN/tutorials/make-your-own-arcade-classic
自留备份用,可以对照教程来看。在页面下载完实例之后就会在默认浏览器中弹出教程
由于版本更新不同,不贴教程里的所有图片
专栏里的链接不指向任何地方,原文档里全是指向内部链接。所有的Next都在原文档里
B站这个专栏编辑器真难用,去抄简书啊!还不让贴外部链接复制内容还自动加一堆后缀什么虫豸玩意儿
This tutorial will take you through the process of creating a small game using GameMaker Studio 2, with the aim to get you familiarised with the interface and the work flow. The game we've chosen for this tutorial is a typical asteroid shooter game, which we'll call Space Rocks. Almost all novice programmers make this game at some point, as it's a fun game to play, but fairly simple to make and shows all the most basic components of a game - things you'll find in the most basic arcade game up to the most advanced RPG - like movement, logic and gameplay design.
本教程将带领你体验完成使用GameMaker Studio 2创建一个小游戏的过程,目的是让你熟悉界面和工作流程。我们为本教程选择的游戏是一个典型的小行星射击游戏,我们称之为太空岩石(Space Rocks)。几乎所有的程序员新手都会在某些时候制作这个游戏,因为它是一个有趣的游戏,但制作起来相当简单,并展示了游戏的所有最基本的组成部分--你会在最基本的街机游戏到最先进的RPG游戏中发现的东西--如运动、逻辑和游戏设计。
We know that getting started with any new skill or tool can be tough at first, which is why this tutorial will attempt to make the introduction to game making as smooth and fun as possible. The tutorial itself is split into 4 parts which are listed below and also available from the drop down menu at the top of the tutorials tab:
我们知道开始使用任何新的技能或工具都会很困难,本教程将试图使游戏制作的介绍尽可能顺利和有趣。教程本身分为以下4个部分,也可以从教程标签顶部的下拉菜单中找到。
1 - 设置和移动
2 - 攻击和碰撞
3 - 得分、血量和效果
4 - 声音效果和抛光
Each chapter is also accompanied by a short video that takes you through each of the steps outlined in text, and you can close GameMaker Studio 2 at any time in the progress of this tutorial (saving your project first!) and when you next load the project you will be taken to the place where you left off. If you wish to play around with what you have learned so far, we recommend that you save the project in its current state - so that you can continue from the same point later - then save it again with a different name and edit the renamed project so as not to lose or change anything that is important to future chapters.
每一章都有一个简短的视频,引导你完成文本中概述的每一个步骤,你可以在本学习教程的任何时候关闭GameMaker Studio 2(一定先保存项目再退出!),当你下次加载项目时,项目会加载上次制作的进度。如果你想先玩玩你目前所学项目,我们建议你以目前的状态保存项目--这样你以后就可以从同一点继续下去--然后以不同的名字再次保存,并编辑重命名的项目,以免丢失或改变对未来章节重要的东西。【阶段性保存副本,但是这样挺占内存的】
Note that the video overlay window can be closed and opened separately, so if you close it by mistake you can either click one of the links given at the start of each chapter (and listed below too), or you can go to the Window menu in the IDE and select Tutorial Windows. Also note that you can access the chapter list from the Playlistin the top left-hand corner of the player and select the required video from there too.
请注意,视频全屏可以单独关闭和打开,所以如果你错误地关闭了它,你可以点击每章开头给出的一个链接(下面也有列出),或者你可以进入IDE中的窗口菜单,选择教程窗口。还请注意,你可以从播放器左上角的播放列表图标进入章节列表,也可以从那里选择所需的视频。
For those of you that have not used the GameMaker Studio 2 IDE before, we have prepared a short introductory video here, and you can also check out the Quick Start Guide in the manual.
对于那些以前没有使用过GameMaker Studio 2 IDE的人,我们在这里准备了一个简短的介绍性视频,你也可以查看手册中的快速入门指南。
With that said, let's hurry along and get started, so click the "Next" button below to start on the path to making your first game!
说了这么多,让我们赶紧开始吧,请点击下面的 "下一步 "按钮,开始制作你的第一个游戏吧!
In this chapter, we're going to start building our game, but before we do that, we need to just take a moment to think about what we'll actually need. In general, before starting any project, it's a good idea to plan out what you want to achieve, even if it's in very broad terms, as that gives you something to work towards when you sit down to work. NOTE: If you have problems seeing the images in this tutorial, you can expand the tutorial window by dragging the edge into the IDE. NOTE: If you close the accompanying video then you can get it back by clicking here Our tutorial game is going to be called "Space Rocks", and as mentioned in the introduction, it's going to be a game about shooting asteroids and getting high scores:
在这一章中,我们将开始构建我们的游戏,但在这之前,我们需要花点时间考虑一下我们实际需要什么。一般来说,在开始任何项目之前,最好先计划一下你想实现的目标,即使是非常宽泛的条款,因为这可以让你在坐下来工作时有个目标。
注意:如果你看不清本教程中的图片,你可以通过拖动边缘到IDE中来扩展教程窗口。
注意:如果你关闭了附带的视频,那么你可以通过点击这里重新获得它。 我们的教程游戏将被称为 "太空岩石",正如介绍中提到的,这将是一个关于射击小行星并获得高分的游戏。
What does a game like this need? Let's list the two most basic of the gameplay components: First we'll need a ship for the player to control, and it will have to rotate and move forwards as well as shoot. Second we'll need some asteroids for the player to actually shoot at Now, before continuing, you should make sure that the game is set to run at 60FPS. For that you should open the Game Options now (from the Quick Button at the top of the IDE), and set the Game Frames per Second to 60:
这样的游戏需要什么?让我们列出两个最基本的游戏组件。
首先,我们需要一艘飞船供玩家控制,它必须旋转和向前移动,并进行射击。
其次,我们需要一些小行星供玩家实际射击。 现在,在继续之前,你应该确保游戏被设置为以60FPS运行。为此,你应该现在打开游戏选项(从IDE顶部的快速按钮),并将游戏每秒帧数设置为60。【顶端第二排齿轮形状按钮,鼠标停留上方一会会显示“游戏选项”方框,点击弹出“游戏选项”界面。主要设置-全局 中有 [ ]每秒游戏帧数(FPS),在框内填写你想设定的帧数】
With that done, we can now move on to the next part, which is to create the sprites that the game needs. Click "Next" to continue...
完成这些后,我们现在可以进入下一个部分,即创建游戏需要的精灵。点击 "下一步 "继续...
The first sprite we'll make is the "ship" sprite for the player to control. To do this, go to the "Sprites" resource and click the right mouse button and select Create:
我们要制作的第一个精灵(Sprites)是供玩家控制的 "飞船 "精灵。要做到这一点,进入 "精灵 "资源,点击鼠标右键,选择创建。【应该是软件更新,在新建的项目界面右侧中文叫“资产”英文是“Assets”的菜单栏中有“Sprites”,右键创建一个名字为“spr_ship”的精灵。注意Scripts和Sprites的区别,前者是脚本后者才是精灵。我现在使用的版本创建时会出现一个弹窗可以设置动画图片等等】
This will open the sprite editor and permit you to set the name of the sprite. In this case we'll call it "", as shown in the image above. You may now also need to resize the sprite, as for this game we want it to be 32x32px. To resize a sprite, you simply click on the Resize Sprite button to open up the resize window:
这将打开精灵编辑器,允许你设置精灵的名称。在这种情况下,我们将叫它 "spr_ship",如上图所示。
现在你可能还需要调整精灵的大小,因为在这个游戏中我们希望它是32x32px。要调整精灵的大小,你只需点击调整精灵大小的按钮来打开调整窗口。【如果不小心关闭窗口,在右侧找到“spr_ship”然后双击即可弹出刚刚的界面。新界面Sprite: spr_ship中左侧image-Size下面有个四个箭头的按钮,点击即可修改大小,点击apply保存。点击Edit Image按钮可以画像素画】
With that done, the next thing to do is create our sprite in the Image Editor. You can open this by clicking on the Edit Image button, which will bring up the editor with a blank canvas ready for you to start drawing:
完成这些后,接下来要做的是在图像编辑器中创建我们的精灵。你可以通过点击 "编辑图像 "按钮来打开它,这将使编辑器出现一个空白画布,供你开始绘制。
Our sprite is going to be a simple line-drawn polygon, much like an arrow head, so let's draw that now. First you should probably enable the grid overlay and set the grid to 8x8px (this will help you to position the drawing tool):
【介绍多边形工具和网格工具(辅助网格线)】我们的精灵将是一个简单的线描多边形,很像一个箭头,所以现在让我们来画一下。首先,你可能应该启用网格覆盖,并将网格设置为8x8px(这将有助于你定位绘图工具的绘画位置)。
Now we can draw the sprite using the Draw Polygon tool (be sure to click the top left of the icon to get the outline tool and not the fill tool):
【四边形、圆形、多边形工具都有线条和填充两种模式】现在我们可以使用多边形工具来绘制精灵(请确保点击图标的左上方以获得轮廓工具而不是填充工具)。
Once you're happy with the result, simply close the Image Editor workspace and the image will be saved to the sprite. We now need to set the sprite's origin, which is the value which will be used as its top-left position when it is drawn in-game. We want our ship to rotate around its middle, so we need the origin at the centre of the sprite.:
【设定精灵的中心点/原点作为旋转的中心点】画完所需图形之后,关闭图像编辑器工作区,图像就会被保存到精灵上。我们现在需要设置精灵的原点,也就是在游戏中绘制时作为其左上方位置的数值。我们希望我们的船能围绕它的中心旋转,所以我们需要把原点放在精灵的中心。
【原点的位置是像素画每一个画构成像素的线的交叉点确定的,不是确定在中心的像素块上】
We can now go on and make the asteroid sprites. So, for this, you'll need to create three new sprites, as we are going to make three different sizes of asteroid. Call the sprites "spr_asteroid_small", "spr_asteroid_med" and "spr_asteroid_huge". All the sprites will have been created at the default image size, so you will want to change their size to be 16x16px, 32x32px and 64x64px respectively (as shown at the beginning of this article). When finished, you can take a moment to draw the asteroids, again using the outline polygon tool to create some irregular shapes. You can see some examples below (shown at twice the size required for the game):
我们现在可以继续制作小行星的精灵了。因此,你需要创建三个新的精灵,因为我们要制作三种不同大小的小行星。将这些精灵称为 "spr_asteroid_small"、"spr_asteroid_med "和 "spr_asteroid_huge"。所有的精灵都将以默认的图像尺寸创建,所以你要把它们的尺寸分别改为16x16px、32x32px和64x64px(如本文开头所示)。完成后,你可以花点时间来绘制小行星,同样使用轮廓多边形工具来创建一些不规则的形状。你可以在下面看到一些例子(以游戏所需尺寸的两倍显示)。
【推荐稍微探索一下制作像素动画,加关键帧、设置帧数多点点按钮就找到了】
When finished, make sure the origin for each of the sprites is set to Middle Centre. The idea now is that the asteroids in our game will start of huge and then break into the medium and smaller parts as the player shoots them. NOTE: This tutorial has created a TutorialResources folder for you within the project files, and if you open the file explorer to load a sprite rather than create your own, it should open on the project location where you can find the sprites used in the "Sprites" sub-folder of the "Tutorial Resources" folder. If you have any issues, you can also find the images here. It's now time to make some objects, so click "Next" to continue...
完成后,确保每个精灵的原点都被设置为中间中心。现在的想法是,我们游戏中的小行星开始时是巨大的,然后随着玩家的射击而分成中等和较小的部分。
注意:本教程在项目文件中为你创建了一个TutorialResources文件夹,如果你打开文件资源管理器加载一个精灵,而不是创建你自己的精灵,它应该在项目位置上打开,你可以在 "教程资源 "文件夹的 "精灵 "子文件夹中找到所用的精灵。如果你有任何问题,你也可以在这里找到这些图片。 现在是制作一些对象的时候了,请点击 "Next "继续...
【我们生成的图片都是png格式的,图片大小(宽高)和我们在引擎里设定的一样】
Let's jump right in and make our first object. As we did with sprites, simply go to the "Objects" resource and click the right mouse button and select Create to create the object. Give it the name "" to identify it, and then assign it the ship sprite we made earlier. To assign the sprite, click the button that currently says "No Sprite" and select the sprite "":
让我们看向右侧工具栏,制作我们的第一个对象。正如我们对精灵所做的那样,只需进入 "对象 "资源,点击鼠标右键,选择创建来创建对象。给它起个名字 "obj_ship "来标识它,然后把我们之前制作的飞船精灵分配给它。要分配这个精灵,点击当前显示 "没有精灵 "的按钮,然后选择精灵 "spr_ship"。
While we're at it, we'll also create an asteroid object, so do that now (create a new object) and call it "". Assign this object any one of the asteroid sprites that you created. We don't need to worry about which one, as we're only going to have a single asteroid object in the game, and we'll set the (the sprite the object will draw) using code in the Create Event. We'll come to that part in a moment, but first we'll do an experiment... Click "Next" to continue...
当我们创建完飞船,让我们再创建一个小行星对象,所以现在就创建一个新的对象,并将其称为 "obj_asteroid"。将这个对象分配给你创建的小行星精灵中的任何一个。我们不需要担心是具体的哪一个,因为我们在游戏中只有一个小行星对象,我们将使用创建事件中的代码来设置 sprite_index(该对象将绘制的精灵)。我们稍后会讲到这一部分,但首先我们要做一个实验...
点击 "下一步 "继续... 【原教程里的Next】
All projects in GameMaker Studio 2 start with a room already in the resource tree called "". This means we don't need to create one for now, but you should rename this room to "" so it has a less generic name (this is done by performing a slow double-click on the name in the resource tree and then typing the new name). Now, what happens if we add instances of our objects to the room and test it? Let's find out! Open the Room Editor by double clicking on the room in the resource tree. When the Room Editor opens, you'll see a lot of new tabs appear in the IDE. We're not going to worry too much about them right now, so just click and drag an instance of the object "" into the room:
GameMaker Studio 2中的所有项目开始时,在资源树【也就是右侧“Assets/资产”一栏】中已经有一个叫做 "Room_0 "的房间。这意味着我们现在不需要创建一个,但是你应该把这个房间重命名为 "rm_game",这样它就有了一个与众不同的名字(这可以通过在资源树中缓慢地双击这个名字,然后输入新的名字来完成。或者使用F2来更改名称)。现在,如果我们把我们的对象的实例添加到房间里并测试它。
通过双击资源树中的房间来打开房间编辑器【快速双击房间直接跳转】。当房间编辑器打开时,你会看到IDE中出现很多新的标签。我们现在不打算过多地关心它们,只需点击并拖动一个对象 "obj_ship "的实例到房间中。
Now drag in a few instances of the object "", so that it looks like this:
现在拖入对象 "obj_Asteroid "的几个实例,使其看起来像这样。
【随便拽几个制作的怪物进来分散在飞船周边】
If you click the Play quick button now, the game will compile and you should see a window open with the instances we've placed in the room visible:
如果你现在点击快速运行按钮【齿轮那一栏的小三角按钮,快捷键F5】,游戏将被编译,你应该看到弹出了一个窗口,窗口里有我们放置在房间里的物体。
Okay, that's not very interactive, but it's a start! Seeing the game like this though does show up a minor problem... the game window is too big. We want the game to have a retro feel, so that means a smaller resolution and play area. Close the game window and go back to the room editor now. We are going to edit the size of the room, so go to the Room Properties and change the Width and height to 500px each:
首先这个游戏并没有任何互动,但我们刚刚开始并没有添加任何脚本。而且还有个很严重的问题:游戏窗口太大。我们希望游戏有一种复古的感觉,所以分辨率和游戏区域要小一些。关闭游戏窗口,现在回到房间编辑器中去。
我们要编辑房间的大小,所以进入房间属性,将宽度和高度都改为500px。
This will change the room size, but may leave some instances outside of the room. You can simply click on them then drag them back into the playable room area. If you test play the game again, you can see that the game window is a much more appropriate size. NOTE: The game window is not just governed by the room size as you can use cameras and viewports to change the window size and change what is visible inside a room. For example, to only show smaller areas of a larger room. This isn't covered in this tutorial, but look up Cameras in the manual for more information. We can now go back to our game objects and start to add some logic into them so they actually do something... Click "Next" to continue...
这将改变房间的大小,但可能会把一些实例留在房间之外。你可以简单地点击它们,然后把它们拖回可玩的房间区域。【或者在左侧中间的窗口中按照操作系统的多选逻辑多选物体】
如果你再试着玩游戏,你可以看到游戏窗口的大小更合适了。
注意:游戏窗口不只是受房间大小的制约,因为你可以使用摄像机和视窗来改变窗口的大小,并改变房间内的可见内容。例如,在一个较大的房间里只显示较小的区域。本教程中没有涉及到这一点,但可以在手册中查找摄像机以了解更多信息。 现在我们可以回到我们的游戏对象,并开始向它们添加一些逻辑,使它们真正做一些事情......
点击 "下一步 "继续...【原教程里的Next】
When programming, everything can be broken down to a fairly simply rule:
if this then that
So, all a program does is check if this happens, and if it does then that happens - like, "if a key is pressed then the player will move". Put into a more GameMaker Studio 2 friendly format it would be expressed as
if event then act
Which means that if an event is triggered, then a specific action must be performed. An event is simply a moment in time when something happens, and some events can be triggered once (like the Global Mouse Left Down event) or can be triggered every game frame (like the Step Event). Let's look at how to use these events to make our ship perform an action, in this case, move. You'll need to open the object "obj_ship" (if it's not already open) by double clicking it in the resource tree. When open, you can then click on the Add Event to bring up the Event List:
在编程时,一切都可以被分解成相当简单的规则。【面向对象设计语言的特点】
if 这 then 那
【赋值,此时的“这”已经被“那”覆盖】
所以,一个程序所做的就是检查这个是否发生,如果发生了,那么那个就会发生--比如,"如果一个键被按下,那么玩家就会移动"。如果用GameMaker Studio 2更友好的格式来表达,它将被表述为:【GML,该引擎的脚本语言类似JavaScript或者C类语言】
if 事件 then 行动
【想要设计一个事件就需要“行动”的支持】
这意味着,如果一个事件被触发,那么必须执行一个特定的动作。一个事件仅仅是事情发生的一个时间点,有些事件可以被触发一次(比如全局鼠标左下事件),也可以在每个游戏帧中被触发(比如步骤事件)。让我们看看如何使用这些事件来使我们的飞船执行一个动作,在这个例子中,就是移动。
你需要在资源树中双击对象 "obj_ship"(如果它还没有打开的话)来打开它。打开后,你可以点击 "添加事件 "来调出事件列表。
There are two ways that we can check if the player is moving: What you use in your projects is largely a matter of choice and will depend on how you like to work and the structure of your project. In this case, we are going to use the Step Event, as it can sometimes be clearer to see the game logic where it's all together, so go ahead and add a Step Event now.
我们有两种方法可以检查玩家是否在移动。
使用精确的键盘事件,只有在检测到按键时才会被触发,或使用步骤事件,用代码来检查每一步(游戏帧)的按键。 你在你的项目中使用什么在很大程度上是一个选择问题,将取决于你喜欢如何工作和你的项目的结构。在这种情况下,我们将使用步骤事件,因为有时可以更清楚地看到游戏逻辑的全部内容,所以现在去添加一个步骤事件。
【在菜单栏中找到step-step,step中的第一项,弹出一个obj_ship:Step的框】
We're going to add some code here, and it will be run 60 times every second. Why? Because we set the game speed to be 60, which means that there will be 60 game frames ("steps") for every second that passes, and since the Step Event is triggered every game frame, any code we add into this event will be run 60 times each second too. The basic interpretation of what we want to do first would be "if the left key is pressed, rotate the ship to the left". To get this into code we need to structure it like this:
if (expression) { <statement> <statement> <statement> }
我们将在这里添加一些代码,它将每秒钟运行60次。这是为什么呢?因为我们将游戏速度设置为60,这意味着每秒钟会有60个游戏帧("步骤"),由于每一个游戏帧都会触发 "步骤事件",我们添加到这个事件中的任何代码也会在每秒运行60次。
我们首先要做的事情的基本解释是 "如果左键被按下,将飞船向左旋转"。为了将其转化为代码,我们需要这样构造它:【这个只是例子】
if (expression) { <statement> <statement> <statement> }
So, we have our "if" at the start and we'll be checking whatever expression goes inside the parenthesis to see if it evaluates to a or a result. So something like "" checks to see if a variable is exactly equal to 1 and if that is then it will go on to perform the code that you have in the . NOTE: In general you'll want to use a double equals "" for checking a value, and single equals "" for assigning a value. Let's add the actual code into the Step Event of the "" now:
所以,我们在开头有一个 "if",我们将检查小括号()内的任何表达式,看它评估的结果是真还是假。所以像 "if (my_variable == 1) "这样的句子会检查一个变量是否正好等于1,如果是真的,那么它将继续执行你在{}中的代码。
注意:一般来说,你想用双等号"=="来检查一个值,而用单等号"="来分配一个值。 现在让我们把实际代码添加到 "obj_ship "的步骤事件中。
if (keyboard_check(vk_left)) { image_angle = image_angle + 5; }
Here we check the function keyboard_check() to see if the left arrow key is being held down, and if it is (the function will return if it is or if it's not) then we add 5 to the image_angle of the instance. The variable governs the angle at which the assigned sprite will be drawn. Note that at the end of each statement we add a semi-colon , which is the code equivalent of the full-stop at the end of a sentence. NOTE: is an instance variable which is a variable that all instances of objects will have. There are many different instance variables, and all of them will be useful to you at some point while creating your games, so take a moment to find out more reading the manual. Why are we adding 5 if we are turning left? That's because angles in GameMaker Studio 2 go anti-clockwise with 0° being to the right:
在这里,我们通过调用函数keyboard_check(),看是键盘否按住了左键,如果是的话(该函数将返回true,如果不是的话,则返回false),然后我们在实例的image_angle上加5。image_angle变量控制着指定精灵的绘制角度。请注意,在每个语句的末尾,我们都要加上一个分号;,这相当于句子末尾的句号的代码。
注意:image_angle是一个实例变量,它是一个所有对象实例都会有的变量。有许多不同的实例变量,在创建游戏时,所有这些变量都会在某些时候对你有用,所以花点时间阅读手册了解更多。
如果我们向左转,为什么要加5呢?这是因为GameMaker Studio 2中的角度是逆时针的,0°是向右的。
【逆时针+度数,顺时针减度数】
This is why we made our ship sprite facing right - it makes setting the angles when rotating much easier! We can use almost the exact same code for turning the ship to the right, so copy the lines of code for the left key (you can select the lines and then use Ctrl/ Command +D to duplicate them) and then make the following changes:
我们可以使用几乎完全相同的代码将飞船转向右边,所以复制左键的代码行(你可以选择这些行,然后使用Ctrl/ Command +D 来复制它们),然后做以下修改。
if (keyboard_check(vk_right)) { image_angle = image_angle - 5; }
You can press the Play button now, and if you press the left/right arrow keys you should see your ship instance rotating.
你现在可以按下运行按钮,如果你按下键盘上的左/右方向键,你应该看到你的飞船实例在旋转。
We are now ready to make the player ship move! Click "Next" to continue...
我们现在已经准备好让玩家的飞船移动了! 点击 "下一步 "继续...
to be Continued →