Game Update 3 – Upgrade notifications via events


  • Share on Pinterest

This week I turned my attention to the UI indication that an upgrade is available on a given tab. Whilst there is only one tab currently working, it is important to plan now for the future.

The idea is simple, you have an available upgrade on a tab, and the game needs to get your attention. I am opting for a simple Red indicator on the tab in question, as this animation shows.

When an option is available, it will be displayed and hidden the rest of the time, a simple idea that needs careful planning. The worst thing you can do is hard code any kind of UI connection.

Trust me, you'll regret it as the code gets more complex and the game more feature-rich.

How do you achieve this?

Great question. I have the answer, Custom events!

This idea exists in many programming languages and is a good way to have actions take place without the need to reference them directly in code.

There are two parts, and I'll use my example above.

The Listener/Receiver

The UI tabs have a Red circle, and each tab has some code that says, “Hey, I'm listening for an event with a specific name.” When that event is received, the code is executed. In this case, the Red circle is set to display. I also have an opposite custom event to hide the Red circle.

At first, this might seem overkill for what I need but think about the future. This gives me an event I can fire anywhere in the game, and the correct action will take place without me needing to update any code or reference any UI elements.

The Transmitter

Now that I have something listening for a custom event in the application, I need a way to broadcast that event.

This is where the transmitter comes in. When I need the Red indicator to show, I can transmit the custom event by name, and everything will happen as expected.

For this example, if the player has enough units of a certain type to purchase an upgrade, the event is transmitted, and the indicator is displayed.

If I need to hide the indicator, I can similarly transmit the event to hide it.

All without needing to reference UI elements directly within my code.

Brilliant, right? This keeps the code clean and lean. If I need something else to respond to the same event, I can just write a receiver and make it do what I need.