Hi there, I'm Wei Ciao. Before becoming an iOS developer, I was a game programmer working for a company making MMO genre games. My primary skills and fondness in programming languages are C++ and Lua. As a game developer, I’ve dug deeply in Lua and developed a game framework based on it.
Here is the combination of programming languages utilized in my game apps:
- C++: General abstract framework can be used in cross-platforms.
- Objective-C: Handling iOS platform-specific details and OpenGL ES implementation.
- Lua: Data description. User interfaces. Game logic. Anything else.
With Lua, I can easily describe a game object simply based on components. In the example above, the game object, Player, is composed of 3 components, which are:
- Transform: In charge of translation, rotation and scaling in game world.
- Quad: A simple quad drawn in 2D plane to represent the object.
- BoundingBox: Collision detecting in box-shaped.
One object can comprise several components, however, not every component needs to be updated and/or rendered. Unlike traditional object-oriented architecture, in component-based architecture we can update and render the game objects accordingly.
What we called a game object, actually is nothing more than a container. Game object doesn’t need to be involved in how specific game components function. It merely contains and manages them in an abstract way and all tasks are assigned to its components. Powers are delegated to the game components.
For example, when a game object consists of Interpolator game component, we can interpolate a variable between the starting value and the ending value, and then apply it to image alpha or scaling. Interpolator will make your objects and interfaces look bouncing and vivid if used properly.
As for memory management, Lua takes no responsibility. All dynamically memory-allocated objects are created in C++ and passed-by-reference for Lua to utilize. Lua only gets pointers. Lua could perform complex memory management tasks, but a clear separation between C++ and Lua helps making memory management less error-prone.
Lua is lightweight, robust and cross-platform. Programming in Lua can save you a lot of compile-time for source files, and the coding process has a quick turnover rate. The higher turnover rate is, the more iterations you can get. In the process of game development, more iterations help increasing work efficiency and improving game quality.
If you are wondering how it works in game apps, you may check out my latest game Bonnie's Brunch 2 and upcoming Jade Ninja.
Live well, happy coding and make great games!
Download full slides: https://speakerdeck.com/halflucifer/designing-a-component-based-architecture-in-lua-for-game-apps
Tutorial: Introduction to Component Based Architecture in Games
(The article has been posted originally on Monkey Potion dev blog)
Follow me on @MonkeyPotion