<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Your First 2D Game on Godot 4 レシピ</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/index.html</link><description>Recent content in Your First 2D Game on Godot 4 レシピ</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://kamera25.github.io/godot_recipes/4.x/games/first_2d/index.xml" rel="self" type="application/rss+xml"/><item><title>Project Setup</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_01/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_01/index.html</guid><description>&lt;p&gt;This first game project will guide you through making your first Godot Engine game. While you don&amp;rsquo;t need any previous experience, it&amp;rsquo;s expected that you&amp;rsquo;ve at least read through the &lt;a href="https://kamera25.github.io/godot_recipes/4.x/g101/start/"&gt;Godot 101: Getting Started&lt;/a&gt; section. There, you&amp;rsquo;ll learn about the editor interface and how to get around the Godot UI.&lt;/p&gt;
&lt;div class="box notices cstyle note"&gt;
&lt;div class="box-label"&gt;&lt;i class="fa-fw fas fa-exclamation-circle"&gt;&lt;/i&gt; Why start with 2D?&lt;/div&gt;
&lt;div class="box-content"&gt;
&lt;p&gt;In a nutshell, 3D games are much more complex than 2D ones. However, many of the underlying game engine features you&amp;rsquo;ll need to know are the same. You should stick to 2D until you have a good understanding of Godot&amp;rsquo;s workflow. At that point, the jump to 3D will feel much easier.&lt;/p&gt;</description></item><item><title>Designing the Player Scene</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_02/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_02/index.html</guid><description>&lt;p&gt;In the last section, we configured the project and downloaded the game art. Now we&amp;rsquo;re ready to start coding - starting with the player-controlled ship.&lt;/p&gt;
&lt;h2 id="setting-up-the-ship-scene"&gt;Setting up the Ship Scene&lt;/h2&gt;
&lt;p&gt;A common part of the Godot workflow is creating scenes. As discussed earlier, a &lt;em&gt;scene&lt;/em&gt; in Godot is nothing more than a collection of &lt;em&gt;nodes&lt;/em&gt;. In most Godot projects, each game object is configured as a scene, with nodes that provide it with the desired functionality, and optionally some code to customize its behavior.&lt;/p&gt;</description></item><item><title>Coding the Player</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_03/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_03/index.html</guid><description>&lt;p&gt;In the last section, we configured the project and downloaded the game art. Now we&amp;rsquo;re ready to start coding - starting with the player-controlled ship.&lt;/p&gt;
&lt;h2 id="adding-a-script"&gt;Adding a script&lt;/h2&gt;
&lt;p&gt;Writing scripts and attaching them to nodes and other objects is how you build behavior and game mechanics into your game. Our &lt;code&gt;Player&lt;/code&gt; scene displays the ship, defines its collision hitbox, etc., but it can&amp;rsquo;t move, and nothing would happen if it collided. We&amp;rsquo;ll write code to add this functionality to the ship.&lt;/p&gt;</description></item><item><title>Bullet Scene</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_04/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_04/index.html</guid><description>&lt;p&gt;Now that the player can move around the screen, our next step will be to implement shooting&lt;/p&gt;
&lt;h2 id="reusable-objects"&gt;Reusable objects&lt;/h2&gt;
&lt;p&gt;The player will fire many &amp;ldquo;bullets&amp;rdquo; during the game, but all of them will be identical. A bullet needs to do the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Appear just ahead of the player&lt;/li&gt;
&lt;li&gt;Travel forward until going off the screen&lt;/li&gt;
&lt;li&gt;Detect collisions with enemies&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since all bullets will do these same things, we can save ourselves a great deal of work by designing one &amp;ldquo;prototype&amp;rdquo; bullet, and using that as the blueprint for creating as many duplicates as we need. Godot&amp;rsquo;s scene system is ideal for this.&lt;/p&gt;</description></item><item><title>Shooting</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_05/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_05/index.html</guid><description>&lt;p&gt;The &lt;code&gt;Bullet&lt;/code&gt; scene provides us with a reusable object we can &lt;em&gt;instantiate&lt;/em&gt; whenever the player shoots.&lt;/p&gt;
&lt;h2 id="adding-to-the-player"&gt;Adding to the player&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s head back to the &lt;code&gt;Player&lt;/code&gt; script and add a few new variables:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-gdscript" data-lang="gdscript"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#d08770"&gt;@export&lt;/span&gt; &lt;span style="color:#81a1c1;font-weight:bold"&gt;var&lt;/span&gt; cooldown &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; &lt;span style="color:#b48ead"&gt;0.25&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#d08770"&gt;@export&lt;/span&gt; &lt;span style="color:#81a1c1;font-weight:bold"&gt;var&lt;/span&gt; bullet_scene &lt;span style="color:#eceff4"&gt;:&lt;/span&gt; &lt;span style="color:#8fbcbb"&gt;PackedScene&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;var&lt;/span&gt; can_shoot &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; &lt;span style="color:#81a1c1;font-weight:bold"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The two &lt;code&gt;@export&lt;/code&gt; variables let you configure them in the &lt;strong&gt;Inspector&lt;/strong&gt; so that you can adjust the cooldown time. Set the &lt;code&gt;bullet_scene&lt;/code&gt; by clicking the property and choosing the &lt;code&gt;bullet.tscn&lt;/code&gt; file.&lt;/p&gt;</description></item><item><title>Main Scene</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_06/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_06/index.html</guid><description>&lt;p&gt;Before we can make enemies, powerups, or any other game objects, we need a place where they can all exist together with the player. In most games, this would be called a &amp;ldquo;level&amp;rdquo; or &amp;ldquo;main&amp;rdquo; scene, and that&amp;rsquo;s what we&amp;rsquo;ll call it here.&lt;/p&gt;
&lt;p&gt;Start the scene with a &lt;i class="gd-Node2D"&gt;&lt;/i&gt;&lt;code&gt;Node2D&lt;/code&gt; called &amp;ldquo;Main&amp;rdquo; and save it.&lt;/p&gt;
&lt;h2 id="creating-the-background"&gt;Creating the background&lt;/h2&gt;
&lt;p&gt;Add a &lt;i class="gd-Sprite2D"&gt;&lt;/i&gt;&lt;code&gt;Sprite2D&lt;/code&gt; child. Name this sprite &amp;ldquo;Background&amp;rdquo; and add the &lt;code&gt;Space_BG (2 frames) (64 x 64).png&lt;/code&gt; as its texture.&lt;/p&gt;</description></item><item><title>Enemies</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_07/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_07/index.html</guid><description>&lt;p&gt;Now that our player can shoot, let&amp;rsquo;s give them something to shoot at.&lt;/p&gt;
&lt;h2 id="setting-up-the-scene"&gt;Setting up the scene&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ll use an &lt;i class="gd-Area2D"&gt;&lt;/i&gt;&lt;code&gt;Area2D&lt;/code&gt; for the enemy, since we need it to detect overlap - either with the player&amp;rsquo;s bullets, or with the player itself.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s are the nodes we&amp;rsquo;ll need:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Enemy: &lt;i class="gd-Area2D"&gt;&lt;/i&gt; Area2D
&lt;i class="gd-Sprite2D"&gt;&lt;/i&gt; Sprite2D
&lt;i class="gd-CollisionShape2D"&gt;&lt;/i&gt; CollisionShape2D
&lt;i class="gd-AnimationPlayer"&gt;&lt;/i&gt; AnimationPlayer
MoveTimer: &lt;i class="gd-Timer"&gt;&lt;/i&gt; Timer
ShootTimer: &lt;i class="gd-Timer"&gt;&lt;/i&gt; Timer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Select the area node and click the &lt;strong&gt;Node&lt;/strong&gt; tab next to the &lt;strong&gt;Inspector&lt;/strong&gt;. Under &lt;strong&gt;Groups&lt;/strong&gt;, type &amp;ldquo;enemies&amp;rdquo; an click &lt;strong&gt;Add&lt;/strong&gt;. Remember the code we wrote on the bullet? It looks for objects in the &amp;ldquo;enemies&amp;rdquo; group.&lt;/p&gt;</description></item><item><title>Enemy Shooting</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_08/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_08/index.html</guid><description>&lt;p&gt;Now that our enemy can shoot, let&amp;rsquo;s give them something to shoot at.&lt;/p&gt;
&lt;h2 id="enemy-bullet-scene"&gt;Enemy bullet scene&lt;/h2&gt;
&lt;p&gt;Make a new &lt;code&gt;EnemyBullet&lt;/code&gt; scene just like you made the player bullet earlier. We won&amp;rsquo;t go into all the steps here, but you can refer back to that part if you&amp;rsquo;re stuck. The only difference here is that you can use the &lt;code&gt;Enemy_projectile (16 x 16).png&lt;/code&gt; image instead.&lt;/p&gt;
&lt;p&gt;The script will be a little bit different:&lt;/p&gt;</description></item><item><title>UI and Score</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_09/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_09/index.html</guid><description>&lt;p&gt;The last main piece of our game is the &lt;em&gt;user interface&lt;/em&gt; (UI). We need a way to show the player the score and other information. To do this, we&amp;rsquo;ll use a variety of &lt;i class="gd-Control"&gt;&lt;/i&gt;&lt;code&gt;Control&lt;/code&gt; nodes - the nodes Godot provides for building UIs.&lt;/p&gt;
&lt;h2 id="ui-scene"&gt;UI scene&lt;/h2&gt;
&lt;p&gt;Start the scene with a &lt;i class="gd-MarginContainer"&gt;&lt;/i&gt;&lt;code&gt;MarginContainer&lt;/code&gt; and name it &lt;code&gt;UI&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Containers&lt;/em&gt; are &lt;i class="gd-Control"&gt;&lt;/i&gt;&lt;code&gt;Control&lt;/code&gt; nodes that are designed to control the size and position of their children. Using them makes it easier to position and move Control nodes without having to do it manually. The &lt;i class="gd-MarginContainer"&gt;&lt;/i&gt;&lt;code&gt;MarginContainer&lt;/code&gt; makes sure its children don&amp;rsquo;t get too close to the edge.&lt;/p&gt;</description></item><item><title>Starting and Ending the Game</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_10/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_10/index.html</guid><description>&lt;p&gt;Our last step is to add a start button and a &amp;ldquo;game over&amp;rdquo; state to the game.&lt;/p&gt;
&lt;h2 id="starting-the-game"&gt;Starting the game&lt;/h2&gt;
&lt;p&gt;Currently when we run the game, it starts immediately. Let&amp;rsquo;s add a button to start it.&lt;/p&gt;
&lt;p&gt;In &lt;code&gt;Main&lt;/code&gt; as a child of the &lt;code&gt;CanvasLayer&lt;/code&gt;, add a &lt;i class="gd-CenterContainer"&gt;&lt;/i&gt;&lt;code&gt;CenterContainer&lt;/code&gt; and set its layout to &lt;strong&gt;Full Rect&lt;/strong&gt;. Then add a &lt;i class="gd-TextureButton"&gt;&lt;/i&gt;&lt;code&gt;TextureButton&lt;/code&gt; child. Name this button &lt;code&gt;Start&lt;/code&gt; and add the &lt;code&gt;START (48 x 8).png&lt;/code&gt; image as its &lt;strong&gt;Normal&lt;/strong&gt; texture.&lt;/p&gt;</description></item><item><title>Wrapping up</title><link>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_end/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kamera25.github.io/godot_recipes/4.x/games/first_2d/first_2d_end/index.html</guid><description>&lt;p&gt;If you&amp;rsquo;ve been following along, you&amp;rsquo;ve learned a lot of the fundamentals of building games in Godot. We&amp;rsquo;re going to end the tutorial here, since we&amp;rsquo;ve completed the basic game.&lt;/p&gt;
&lt;div class="box notices cstyle tip"&gt;
&lt;div class="box-label"&gt;&lt;i class="fa-fw fas fa-lightbulb"&gt;&lt;/i&gt; The secret to learning effectively&lt;/div&gt;
&lt;div class="box-content"&gt;
&lt;p&gt;Here&amp;rsquo;s my big secret for getting the most out of tutorials like this and others you may find online. At the end, once you&amp;rsquo;ve finished building the project, immediately delete it and start over. This time, try and re-create it without looking at the tutorial. If you get stuck, look at &lt;em&gt;just&lt;/em&gt; that part, then close it again.&lt;/p&gt;</description></item></channel></rss>