fbpx

You can take advantage of libraries and frameworks.

Listen to the full episode to learn how libraries are different from frameworks and where game engines fit into all this. You can also read the full transcript below.

Transcript

Don’t try to do everything yourself. There’s some really good libraries and frameworks that you can use for free or pay only when your game is successful.

Again, this applies to any software project. If there’s code that you need to write to get your project to do something interesting, then there’s a good chance that somebody else has already written the code that you can use.

Need to play some sound effects during your game? There’s code available to do that already. Need to connect your game to other computers or to server computers to coordinate multiple players? There’s code for that already. Need to load image files and draw the images to the screen. Yep, there’s definitely code for that already.

This is the type of code that you don’t want to be writing anyway. It has nothing to do with the specific story in your game. It has nothing to do with how your game is played. Or what rules you decide are important. You need to be focused on the things that make your game unique and fun to play. There’s enough work for that already. Avoid writing code that not only has somebody else already written but has probably done a better job.

Now, that’s not to say you couldn’t do just as good of a job. but there’s usually a lot of little details involved that we don’t normally think about until that becomes our focus. None of us has the time or energy to become expert in everything.

I might have told this story before but it fits well here. I used to have a book about electrical engineering. It was an old book from the early 1900’s. I forget now if it was 1913 or maybe 1906. Somewhere around that time. The interesting thing is that this book contained all the world’s knowledge about electrical engineering at that time. There was even a chapter about how to pour concrete! I studied electrical engineering in college and I can saw that there were no classes about concrete or general construction. But back in the early 1900’s, knowing how to pour concrete was needed for electrical engineers when placing utility poles in the ground. Or maybe when anchoring transformers to the ground.

Today, there’s no way a single book can cover a broad subject such as electrical engineering. There’s too much for a single person to learn at all no matter how many books are involved and no matter what topic. We have to specialize. We have to pick a narrow niche and become really good at that one thing.

When it comes to programming, niches such as sound processing, video processing, and networking all have experts who’ve studied the problems and have written libraries that hide all the details so it looks easy from the outside. That’s perfect.

If you try to do all this yourself, you may not finish at all. And if you do, your code probably won’t be able to accomplish nearly as much. And it’ll probably have bugs caused by not spending enough time to learn all the details.

When you have code that you include in your project to help you with a focused need such as playing audio in your game, this is called a library.

We normally think of libraries as a place containing lots of books. A software library will contain classes and methods you can use in your code just as if you had written the classes and methods yourself.

You might need to adapt a little to the author’s way of thinking. Maybe the library names the methods with different uppercase letters than what you use in the rest of your code. Maybe the author has an interesting way of passing method arguments that’s different than your own style.

And things get more involved when you start using multiple libraries and each library has its own way of doing things. That’s just the way libraries are.

A framework is a little different. These are bigger than libraries. A framework goes beyond just a small focused need and will offer help with structuring your entire application.

To give you an idea of the difference, imagine you run a small restaurant. Using a library would be like hiring an employee to wash dishes. This person might do things a bit differently than you would if you were washing the dishes. But as long as the dishes come out clean, you probably don’t mind. Using a framework would be like shutting down your own restaurant and opening a franchise McDonalds. This can be very profitable but you lose almost all ability to make any decisions yourself. Now you have to follow the rules of the framework which seems to have a rule for everything.

There’s room to adapt your code so it can use multiple different libraries. But once you decide to adopt a framework, there’s not going to be another one.

A term you might hear often is something called a game engine. Depending on the game engine, this could be more like a library or more like a framework. Personally, I’d classify most game engines as leaning more towards the framework side. Maybe not all the way in all cases though. Because some game engines work okay with other game engines. So you might have one game engine that focuses on the video aspects of your game while another one takes care of the physics calculations.

If we go back to the restaurant example, this would be like hiring a team of people to wait on tables while another team prepares the food. Each team is more than just a focused solution but not quite enough to take over the whole restaurant.

Other game engines are more complete and fully capable of running the entire show. This is one of the problems I’ve had with game engines. Especially when trying to learn how to program at the same time. It becomes hard to separate what is general programming knowledge from what is specific to the game engine.

This is why when teaching programming, I tend to avoid the big game engines. Sure they can give you some really impressive results with just a little work. But I never felt like this was a good way to learn how to program. I prefer smaller game engines such as SFML. This is the Simple and Fast Multimedia Library and it provides a lot of high quality code that can help you with the basics of creating a 2D game.
But even that has a lot of code that gets in the way of learning how to program. That’s why I started building a text based game. The only problem is that the only really complete text based library is Curses. And Curses is really old. It needs some help to make it easier to use and more consistent with how the rest of C++ works.

If you want to get involved and learn how to program as I work on this library, then the best way is to become a patron and selecting a reward level that fits your needs. Just visit takeupcode.com and click the link to “Become a Patron.” Do this now so you can get involved from the beginning. If you’re interested in how to start building your own video game, then participating in building a video game will give you the direct experience that you’ll need.