This is the eighth part of the “Everyone can Make Games” series. This series of tutorials is aimed at absolute novices who have no experience in game development. It’s not too difficult to make a micro channel game, and you can do it too.

The small game development tool used in the tutorial is wechat official small game production tool: wechat small game production tool

If you are interested in game development, please follow my wechat official account: Little Ant Game Development.

In this section we’ll focus on a common tool used in game development — notifications, also known as events.

The concept of notification

As mentioned earlier, notification can be understood as sending a message to someone else, and the process involves two parties, one sender and one receiver. The sender is responsible for sending the notification, and the receiver decides what to do with it once it has received it. Notifications can be “one to one” or “one to many”, such as “single chat” and “group messaging”. Notifications are frequently used in game development and are the most important means of communication between objects in the game world.

Now that you understand the concept of “notifications”, let’s jump right in and create a notification and use it to communicate between two objects.

Create a notification

Click the “New Notification” button in the rightmost data area.

Give the notification a name in the popup box. Here it will be called “warplane clicked”. Then click ok.

If you look at the notification section of the data area, you can see a notification called “fighter clicked”.

Tip: As with variables, clicking on a notification will bring up a red circle with a minus sign to the left, which will remove the notification.

Now that a notification has been created, let’s use this notification to implement a feature that adds a number in the game to show how many times a fighter has been clicked.

Here’s how it works: when we click on a fighter, the fighter sends a “fighter clicked” notification to the number, and when the number receives a “fighter clicked” notification, it increases its display value by one.

First, we added a new type of material to the game: numbers. By the way, a little review of how to import material into the game.

In the Resource Management area, click the “Add Stories” button.

Select “Building block Y”, “White number” and click the “Import” button.

A “white number” resource appears in the resource management area, a “white number” layer appears in the hierarchy management area, and a white number 0 appears in the editing area.

Next, we configure the sender of the notification, which is our “warplane”.

The sender of the notification is configured

Select “warplane” in the hierarchy, then click the “Add Event” button in the block area, and select the “When the Sprite is clicked” event.

There will be a block in the block area, which means that when our planes are clicked in the game, we will receive a “when the Sprite is clicked” notification, and after receiving the notification we need to do some things of our own.

Please note that in this case our aircraft is acting as the “receiver” of the notification, so who is the sender? What the hell, all we care about is what we need to do when the fighter gets clicked.

The next thing we need to do is to select “controls” on the right side of the block area and drag the block that says “inform everyone that warplanes are clicked” into the block that says “when sprites are clicked”.

It looks like this.

Notifications are sent to “everyone” by default, but we only want to send numbers in the game. Click the “All” drop – down box and select white numbers ->(Scene 1) White numbers.

In the end it looks like this, very pointedly sending a “warplane clicked” notification to “white number in scene 1”.

Tip: “warplane clicked” is the notification we created in the data area. You can click the drop-down button to the right of “warplane clicked” on the block to switch to other notifications that have already been created.

This way our “sender” is configured so that when we click on a fighter in the game, it sends a “white number” notification that the fighter has been clicked.

Click “Preview scene” and then click on your fighter to see what happens.

Nothing happened…

That’s because we just sent the notification, but the recipient hasn’t responded to it yet.

Configure the recipient of the notification

Now, let’s configure the recipient to add some responses.

Select the “White number” in the hierarchy, then click the “Add Event” button in the block area, and select the “When notified” event.

A block like this will be added to the block area. Its function is to receive “aircraft click” notification, similar to the function of an antenna.

Next we do something by selecting the “Appearance” TAB on the right and dragging the “Increase my value by 1” block into the block area.

So it’s going to look something like this. It means: when I receive a “warplane clicked” notification, I increase my value by 1, like “0,1,2,3,4,5,6……”. Let’s count.

Once the receiver is configured, click the “Preview Scene” button again and click “White fighter” in the game to see if the white value starts to increase with your click.

To summarize

We learned the concept of notifications, created notifications in the game, and used notifications to “communicate” one-to-one between two objects in the game.

practice

Notifications are going to be used a lot in game development, so you can try the following exercise:

  • When clicking on a red enemy, the white number is reduced by 1.

  • When clicking on a blue enemy, the white number is reduced by 2.