Game Design Pattern: Flyweight- Game Dev Series 140

Objective: short introduce the Flyweight game design pattern.

Flyweight

In this tutorial, I would introduce another game design pattern, which is the easiest one.
When we create an object, let’s say, a sword.

A sword should be with the following basic data:

When creating a sword with this script attached, it means these data would processed once. However, if you create a thousand swords, even more, ten thousand swords, these data of a sword would processed ten thousand times.

My Mac is screaming for processing these swords!

You might notice that there are some data that would be the same on each sword: main part, sub part, and type.
These are the data that we could make these sword sharing, not just processing every time a sword generate.
This is also the concept of Flyweight game design pattern.

To implement this design pattern, we just make those data that shared the same information as “static”.

That way when a sword is generated, these static data would be stored in the system and can easily to be implemented with other swords.
There should be less resource wasted in game processing.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store