Just a heads-up if you actually found the answer, you put the code in, and all that good stuff, and for the life of you, you cannot get it to work... :s

Under Groups in the key node, click on Manage Groups. You might just see this:

If that is the case, you need to select the Area2D node in this window, and then click on "Add". After that, if you did everything else correctly, it will work.

So, onto the locked doors!

Thank you, @> @Nerdzmasterz said:

@DaveTheCoder said: Simulated user feedback:

I tried your tutorial, but it doesn't work. What do I do?

Who was it, and what happened?

Let me know if this fixes it.

I'm trying to get @TwistedTwigleg to switch the location of this series so I can speak to the beginners directly. I will be able to resolve things better then.

Which section doesn't work?

I can post the code.

So there are two schools of thought in terms of building a game. Either make your dream game or start small. Most people say to start small, and this is good to learn programming and game development. But not to actually publish or sell a game. If you make an Asteroids clone and put it on Android, why are people going to play it? Everyone played the original Asteroids and there are like 1 million clones already (same with Breakout, Bejeweled, etc.). There is no reason to play or buy your game.

I would say do some small simple 2D games to start, but don't release them. After you get a little experience, work on the game you want to. Because you will only have motivation if you are working on your dream game. I'm not saying try to make the next World of Warcraft by yourself, cause that's impossible. But cut your idea down to the base and see what is possible. Like if you are making an RPG, does it have to be 3D? Can it be 2D? Can you make it 10 hours long instead of 80 hours? Can you have 5 dungeons instead of 25? Is it okay if there is only 1 main character and not 5 classes? Can you use free or purchased art? Can you use computer generated art (such as for clouds or water, random variation in wood, etc.)? Can you make the map random procedural to cut down design time? Do you need voice acting? Is text good enough? Can you release in 3 episodes so you can start making money sooner and marketing your game, instead of working on it for 3 years in one go? Is there any part of the game that can be outsourced or do you know people that can help for free? Does it have to be multi-platform? Maybe make it only desktop, or only mobile. Doing 5 platforms at once can be time consuming. For example, only releasing on Android at first and seeing how it goes.

There are lots of things you can do to still finish the essence of what you want to create in a reasonable amount of time. And, more importantly, actually finish and release the game. This is key. Most people never finish their game, or they spend 6 years and it flops or the time has passed. It's not worth it to work on something that will take longer than 1 year, unless you have a large team and money. Try to make something that could be done in 6 months or even 3 months. That way you can get feedback, experience, maybe some money, build a following, etc. And definitely post about the game while you work on it. Share screenshots on Twitter or the forum. Do your own blog with code for stuff you figured out. Do YouTube videos. This is important, because you need people to follow you in order to buy your game. Marketing is just as important as the actual development.

If you do all these things, you will probably find some success, provided the game is actually decent, which no one but yourself can guarantee. And it takes time and experience to make a good game. Just like you wouldn't expect to buy a sketchpad and mess around with drawing and be working for Marvel in 3 months, don't expect to make a hit indie game in 3 months. Most of the big games you know about were from people with years and years of experience (either on their own or previous experience at studios). So expect to invest at least 1 year of solid training before you are any good. And if people don't like your game, take the feedback. It probably means you need more experience or didn't execute properly. There will always be haters, but you should be open to feedback, especially while you develop your game. So do your best.

@DaveTheCoder said: Simulated user feedback:

It still doesn't work.

I'll tell you what. If you have any problems with this tutorial, pm me and I will get back to you. In the meantime, I will keep going...

As soon as this gets moved to Tutorials.

"Simulated user feedback" means that I was playing the role of a user asking difficult questions.

You realize I sent that to @TwistedTwigleg ?

However, I still think this will be better in the Tutorials section.

Hello again! Let's pick on the locks next.

What? No, I'm not breaking into anything. Let's just make these things work! :p

So, what does the lock node need to do?

The locks need to:

block the player

need to be removed if the player has a key

need to remove a key from the player upon detecting one

So first off, if the the lock needs to block the player, and it doesn't move, so what sort of node do we need?

A StaticBody2D, of course.

So let's add a new scene, and set the root as a StaticBody2D, and add the Sprite and the collision shape.

Okay, now we name the node Lock.

So, the StaticBody2D will block the player, so check that off the list.

What else do we need?

must be removed if the player has a key...

How does the player have a key?

Well, what do we know about the keys in the player's inventory?

Don't need to be seen

Owned only by the player

Only serve as an amount in the game.

This sounds like a number variable that should go in the Player script.

Perhaps this is about the most brilliant comment I made, I know, but this way of thinking can help you decide on how to handle different aspects of your games.

So, we save the Lock scene, go back inside the player script, and add var keys = 0.

Now, we can replace the print function with:

Save and run.

It didn't do anything.

Actually, if you still had the print function, you would see this in the Output:

Now we just have to delete the key from the game.

We do this with queue_free(). Add queue_free belowkeys += 1.

Wait, the player left and the camera moved?

What happened is, instead of calling the key to disappear, you told the player to disappear.

But how to get tell the key to disappear?

Note that the function we are using has a parameter. What happens when we tell the code to queue_free the area?

The key disappears!

Okay, so now how do we tell the door to go away when the player touches it? It's in the same situation as the key, in that there will be many of them.

Before I give you the challenge, there is something about if statements that you need to know.

if statements do not always check if two things have the same value. What if you want to check if you have more of something in one value over the other?

This is done by swapping == with >.

To check if something is less than, we use <.

To check if something is not equal to something else, we can use !=.

One of these symbols will be needed to check if you have any keys.

So my challenge for you is to add Lock to a group called "lock". After that, identify which symbol you need in the if statement.

Oh, and you have to figure out what signal you will need.

I will give you one hint- the code all goes into the player script.

Now for a reality check:

I understand that it is not "best practice" to put everything in one code. In real life, you actually have a script only do one specific thing, like player movement is on one, player animation is on another, and so on. However, this is only your second tutorial, so don't worry about it for now. Over time, we will make many scripts and set them up properly. :)

Now, just a quick overview of the last section, in case any of you were confused. The assignment was a lot. In real programming, you will occasionally have to deal with trying to figure out what feels like a million things at once.

How do you break it all down?

Well, we've already have dealt with StaticBody2Ds. Now what do we know from experience?

Other physics bodies react to it.

It is not an area.

This means that the signal to use on colliding with it would be body something.

Now what sort of body is it?

So far, we have either body_entered(body) or body_shape_entered(body_rid)

Okay, so which do we use?

First off, what is body_shape_entered, and what is RID...?

Ewww... This signal has a lot of parameters, some of which we have never even used before. Do we even need all these?

Let's try body_entered(body) first.

In the Area2D inside the player, connect the signal body_entered(body) to the player.

Now, we did put the Lock in group "lock", right? How did we do this with the keys, again?

Now this is a nice, we can almost copy/paste from this function- we just have to switch area to body, and change the group name!

Okay... Now, which symbol do we need?

if we have a key... do something.

so, try...

That is my challenge for you this time.

Eh, actually, that's kinda boring, right...?

Let's do something fun after trying to figure out all that by ourselves.

I'll tell you what... the games you have look great, but they're a little bland, right?

So, Another thing you can do is find a nice floor image, maybe some decorations for the game to suit the style you have, and let your imagination run wild!

Alright as we have all our images, there is something you should be aware of about them. Each one of them has a special license. If you want to actually use those assets for a real product, you will have to abide by these license, just as you have to abide by the license for using Godot: https://godotengine.org/license

So, the challenge for you in this very short section, you need to locate the license for all of those images you have grabbed.

This is probably the most boring part of the whole project, so at least it's over. :)

Hello, world-wide-web, how is everyone?

Another thing I wanted to talk about is, what do you do it you want to animate a character? Say your character is several different images. How do we deal with that?

The easiest way is to use an animated sprite.

...

How do we animate sprites?

I'm glad you asked.

If you open up a sprite node, you will see a tab in the inspector titled "Animation". Let's see what that is.

HFrames? VFrames? What is a Frame, even?

Just for the fun of it, increase the HFrames property. What happens?

Mine got chopped in half? What is it doing?

Simply put, it is dividing the sprite based on the amount of frames each sprite has. HFrames divides it vertically, and VFrames divides it horizontally.

Why wouldn't VFrames divide vertically, and HFrames divide horizontally?

I don't know, I didn't design Godot. I just write tutorials about it. :)

However, what if we want to show a different frame? Well, let's mess with the Frames property.

Okay, so the frames will select the next frame in the sprite, based on the amount of HFrames andVFrames.

But what if your animations are a number of images, not just one image with animations?

We could simply change the texture over time, but who wants to do that?

Lets type in our browser, "Godot animated sprite".

The first thing that pops up is something called Animated Sprite in the docs. What does that say?

Great! There's a node for that!

So, let's add a new scene, and search for an animated sprite...

Now hold up. An animated sprite only plays animations. It cannot detect collision or cause collision. It is useful for decorations that you are okay with trampling over, but that's as far as it goes.

Because of this, it might be a better idea to use a body or an area.

Remember when I said I would use the lock sprite for my door? The reason is because, as you saw it, it is a group of images.

Because of this, I will use my door node for this section. If you have another item that animates, you can use that.

I will remove the sprite and add an animated sprite in its place.

Great! Now, how do we animate with it?

What does the inspector show?

The first thing that pops up is Frames. Click on the box next to that, what is that?

A thing that says New SpriteFrames? we've seen frames in a sprite before. Let's click on that as it sounds promising.

Nothing happened.

Click on the new SpriteFrames.

Now, what in the world is all this?

Well, this panel is where you add your images for your animations. Lets say you have an idle animation. In this panel, you can drag and drop the images for the idle animations right into this panel.

We can drag and drop as many images as we want into this panel, and even reuse the same ones as many times as we need for a smooth animation.

Now, what if I need a new animation?

Inside this new panel, there is a section called Animations, and has a little scroll with a plus arrow, and a trash bin. By the looks of it, the plus scroll adds an animation, and the trash bin removes a selected animation.

So, let's add the plus button and name the new animation. Now, we can add images to the new animations.

So, what if my images are on one image?

Well, first off, what other properties do we have in this panel?

Hover over each one with the mouse to see what it does.

One of these properties, when hovered over, says "Add Frames from a Sprite Sheet.

What is a Sprite Sheet?

A quick online search will show you images with multiple animations in them.

This property is what we need.Select it, and then select the sprite sheet that needs animated.

Now, we notice that the images are all divided in a weird way. How do we fix that?

At the top left, we see Horizontal and Vertical... and it has numbers, sort of like HFrames and VFrames.

So, let's use Horizontal and Vertical to divide it so that the images are divided correctly.

Now what?

Now select the frames that you need for your specific animation. I need all of mine, so I will use the button at the top-right that says Select/Clear All Frames. Then click on the button that says it will add the amount of your selected frames.

Great! We see the images, but... the animation isn't playing.

Let's click on the AnimatedSprite again, and check out the properties again.

One of the properties is called Playing... click on that, what does that do?

Now the animations are playing! However, the speed is a bit off, and the animations keep playing. For some animations constantly playing, that's fine, but I don't want my door to keep opening and closing.

Let's work on fixing that first.

What other properties does this panel have...

Loop. What happens if I turn that off?

Hey, the animation now only plays once!

However, now what about the speed-wait. Right above Loop, there is a thing called speed. That must change the speed of the animation.

So, now my challenge for you is to set your animations up the way you want them to play. I will see you in the next one.

Our game is looking great, but, what if we want something to happen when the animation is finished playing? Ie, I want my door to open before I go to the next scene. How do we do that?

How do we tell the code to do something when something takes place?

Signals!

Do animated sprites have signals?

Yes, they do:

For my version of this game, I need the signal animation_finished, so I will connect it to my door.

However, how do we tell the code to play an animation?

When you want the animation to play, you first have to call the animated sprite through code, like this:

Wait a minute, aren't you supposed to cast Animated sprite as a variable, and have it called in ready()?

Technically, yes, but I am only calling mine once in the code.

After that... play?

At the end of the animated sprite, type play():

Now, play is asking for a string variable. This string is the name of the animation that needs to be playing, I suppose, so, in quotation marks, type in the name of your animation.

That's my challenge for you this time- make an animation play.

Hello, beginner indie devs! How are you? Can I get a high-five?

No?

Okay.

So, we have a game that has amazing graphics and animations, right? It looks fantastic! However, if you haven't noticed, our game is still a bit... quiet?

Let's change that

Going back to this site, it also has a lot of different kinds of audio samples which you can download. Check the licenses before download, however, as this is very important- and not just for the sake of learning.

https://opengameart.org/

We are not going to just build a game to learn how to program. When we are done here, we are going to export the game on Itch.io, and I will do this for my game and show you how to do this as well.

Who doesn't love a little fame as a programmer? =)

What is nice about this site in particular is that you can actually go to the left side of the site, and select which licenses you want your assets to have. If you want straight-up CC0, which, IMO, has the least restrictions, you can deselect every other license in that list.

So, I started with just the ambience sound for my game, which is under the CC0 license. Now, this will be the simplest audio for the game, the background sound, so how do we play music?

There's a node for that! =)

It's the AudioStreamPlayer, so let's open up a new scene, and search for it. Now, this is a 2D game, so we want AudioStreamPlayer2D.

In the inspector panel the first thing we see for this is Stream. Let's put our audio into the Stream box. And, we can listen to it by selecting the paying toggle. However, what we want is the Autoplay toggle. Why? Because playing plays it in the editor, not the game. Autoplay, however, plays it in-game automatically.

Now one last thing for this short audio tutorial.

Let's say the audio is supposed to loop, but it is only playing once. What do you do?

If you run into this trouble, select the audio you want to stream, and at the top-left corner there is a tab called Import.

In this tab, you will see some properties. To loop a sound, you must check that, when it was imported, loop was toggled on. If it was not, you simply toggle it on and click on Reimport.

Now, how do we make sound effects that are not ambience, like a sound for opening a door, or grabbing a key?

That's in the next one.

For now, my challenge for you is to find any type of audio- and make sure you check the licenses- and add it to an AudioPlayer2D. Also, if it must loop, then make sure that it does so. I will see you in the next one, and if there is anything in particular you want to see in this tutorial, feel free to PM me, and I will work on implementing it. :)

Hello, again, Indie devs!

Hello, so sorry about the quick bug fix problem in the previous version of this page! I hate bugs. I just want to squish all of them! :p

So, how do we pay different scenes at once? Do we use a node for each scene?

That might work, but... what if you had a sound for losing, one for winning, one for each player pickup, another for shooting lasers, another for explosions, and one for each enemy- and one for each boss, one for each weapon, and the...?

Not the best idea.

What can we do?

Well, we already have two audio stream players... one for the ambience/music, another for the sound effects... Can we use the sound effects ones for multiple sounds?

Yes, we can! We have to set the stream to the audio stream player, and then have it play the sound. How can we do that?

Well, first off, we have to set the stream to a sound. What does that mean? Obviously you set the sound for the player, but how?

You use the codeset_stream()

This set_stream takes a parameter, but what do we use to access the audio?

It's path. However, there is a step before you simply plug it in.

This step is to use load(), and then put the path in the load parentheses.

It might be easier to see it in code... but where do we go from here?

Well, what triggers these sounds? The player. We could attach a signal to the player, but... the player is the only one that is going to even use the sound, so why not add the audio stream player as its child, like this?

Now, as it is a child of the player, we can use get_node("AudioStreamPlayer2D") to grab it. After that, what?

add set_stream() to the end of it. next line, get_node(player's_name).play(), like so:

Now, let's talk a little bit about something I have already mentioned once before: not adding everything in one code.

In this example, here, we can see that the player code is getting very big, very fast. This is why it is not the best practice to pile everything in one code. While this is a tutorial intended to show you the proper way of doing things, I also need it to show you the issues you can easily come across and even create for yourself. Suppose you leave this for a year, and come back. You gave two audio stream players, which one is this pointing to? Also, if you write a document in your player and hand this to someone else, they will be less inclined to even look at it.

Now, my challenge for you is to finish the audio in your game. If you have anything you want to see in the game which isn't here already, pm me and I will try to implement it in. I will see you in the next one.

So earlier, I talked about why you should have one script do one thing. So, does this mean we need to animate the player with the animated sprite?

Yes, of course! That would be an easy start in the right direction.

So, what might our animations for this maze game be?

Idle Walk.

Simple enough. Now, how do we animate something when the player moves? Signals?

Not exactly, there is an easier way to do this. =)

If you look back at the player, under get_input(), it shows what inputs cause the player to move. We can use those exact same inputs for our code in the animation player.

Let's add a script to the Animated Sprite, and copy/paste get_input. We also need to use func _process(delta) for this.

Now, we can remove everything about velocity, and move_and_slide, the animated sprite is not detecting collision. What do we need the code?

play("whatever_animation), like this:

Now... what about if we want it to stop?

Let's look back at the player's get_input(). What else does it have on it?

velocity = Vector2()...

What is that?

If you remember from our test, it kept the player from constantly moving. How?

Vector2() means Vector2(0, 0). If we are not pressing any buttons, velocity will always be 0, 0. This is why the character stops.

So, can we use it? I mean, the Animated sprite is the child, not the parent...

Normally, you would use a signal to get to a parent, but there is another way. Since I want to show you whatever I can, the other method is to write get_node(), and with the Player selected, drag it into those parentheses and see what you get.

Ignore the error for now. This is the child calling its parent directly through ode. Yes, they often use signals for this instead, but this was to show you that you can do it.

Now, how to check the velocity?

Every node grabbed in code can have all of their variables, functions, and whatever else used. You could add .velocity == Vector2(0, 0) right in.

Now we need to finish the if statement with play("idle_animation_name").

And you're done!

However, there is an even easier way to do this! :o

Here's my challenge for you in this round: You have all of the information on how to do this in this post. What can you do to basically turn all of this into two simple if statements?

I will see you in the next one.

Hello, world!

...

I wasn't saying it because it was some intro video.

So, anyways, one thing that I wanted to share with you this time was lighting. I mean, the games look great, don't they? With all the sound and graphics?

However, it's a maze, and the player right now can see through walls and such- it's just a bit weird.

So let's change that.

For this, you will need some light masks. I made some a while back for one game and put them under the CC0 license, so here you go, use them however you want.

https://godotforums.org/discussion/29891/light-masks#latest

Now, what are light masks? Well, let's go into the player and add a Light2D node. In the inspector, you will see something called texture. That is where you put your light mask.

Now, I am only going to use the round one, but you can use either or both.

Now if you save and press play, you will notice things are not lit in your game! However, the walls shouldn't glow. Can we keep certain things from lighting up?

Yes, using the LightOccluder2D.

(And yes, I know I haven't done much to my game yet, I've been busy explaining things to you guys. :) )

So, what we need to do is go into whatever nodes you don't want to light up, in my case, the walls. Now, we only have to do this to the main Wall node, the rest of the copies will gain this ability automatically. So let's add a LightOcclude2D.

Nothing happened.

Of course not, we didn't tell it how it is shaped yet.

In the inspector panel, go to the empty box next to Occluder and click on new OccluderPolygon2D, and then select it.

Next, make sure that you are using this cursor-shaped tool before proceeding, otherwise it will not work:

Now, click on the edge of the sprite of the object you want occluded, and carefully work your way around the shape. You might want to use the snapping tools, which are at the top of the editor.

After that's done, save all and hit the play button!

Wait, you say you everything is still bright?

In the Light2D of the player, there is a tab called Shadows. Click on that, and toggle shadows on.

There, that looks better!

So now, my challenge for you is to add lights to your game. Note that the light2D has a color property- you can change the color of your light! Have fun, and I will see you in the next one.

Hello, everyone. I don't know about you, but... isn't the maze still sort of bright, even with the occlusion?

So very quickly, I am going to tell you about a node that you can use to change that, and that is the CanvasModulate. So, let's go into, say, your first maze, and add one in.

And, the most obvious thing you will see in the inspector is called Color, and it is currently white.

It's not really a challenge, but I would like you to just play with it and have a feel for how it changes your game. :)

Alright. At this point... I'm not going to give you something new to learn, at least in this post- and there will be more learning ones to come.

Right now, I just want you to step back, and look at everything we have already gone over...

For a little maze game.

This is why I said that I wouldn't show you how to make some huge game. This was a lot of effort that you have put into the game we are making already- and a big game will be worse.

With all that being said, we are still not done.

The good news? All that's left is a few finishing touches, and you will finally be able to release your game into the wild.

Give yourselves a pat on the back. You're doing amazing if you were able to come this far! =)