Monday, April 13, 2020

Tutorial 2.8: Recap


We created GxImages, a library, Entities, SpriteAnimations, and what else. By now, I can imagine you might be confused with all the different classes. Who is doing what?


First try to make a difference between “data” and “entities”. Data can be an image, a sound file, or an animation description (how fast, which frames, what next, …). A 3D model, level structure, a shader, and so on. Data tends to eat relative much memory, so we only want to load it once. Or even better, only when needed, on demand. Since the engine itself doesn’t know what we want to load, a “Resources” file has been added to the game code, doing that.

Entities are instances, using that data. They can come in great numbers, like the 20 bonus crates or foes on screen. Multiple entities may refer to the same Data resources. So far we only made a very abstract base entity, and another still pretty global “Sprite” entity. The latter refers to an Image and can play an animation.

First, we fill our ImageLibrary with Images, which are Atlas Textures, meaning a single image file can contain multiple subimages, referred as “regions”. Second, we define animation data. An animation tells which image to use, and each animation frame is linked to a region of that image (atlas). Also non-animated sprites, like a simple rock picture, are treated in the same way here. But only using a single frame.

Entities are made and inserted into the EntitySystem, which updates them every cycle until the entity tells to quit (“kills itself”). If an entity update() function returns false, we shoot it, cut it in pieces, throw it in the trunk, eat spaghetti with mom, then burry it in a forest.


Got it? Good. Now let’s put this thing to action. We’re going to clean up the Game code, and make more use of the engine to … to get the same stupid orb. Joy.

So… You’re saying we did ALL this work for the same Orb? Something we had programmed within the first 10 minutes already? Ehm, yes. C’est bon, oui? Engine programming is a lot of work indeed. You could have cheated as well, and take the short route.

But remember those times when you used to buy flowers and cook for your girl? You could just as well buy her a bigMac and sit in the couch, but that won’t be rewarded on the long term. Quid pro quo, my friend.

Trust me, we made solid basis for further operations here. Lots of sweat digging out all those trenches, but now we are better protected for the Vietcong. All the studying late nights, but now we’re going to get filthy rich. Now we shall harvest.

No comments:

Post a Comment