New components introduced
ParticleFX - how to use simple particle effects. | |
Script - how to use tables and for loops. Introducing pre-hashing for performance. |
Landers | Step-by-step tutorial
Reminiscent of the classic arcade shooter space invaders, aliens from outer space have arrived in a swarm and are about to land. Can you stop wave after wave of their onslaught?
This tutorial assumes you already have a knowledge of the components of building games in Defold including input bindings, game objects, scripts, animation sets and factories. If not, you should attempt the Incoming tutorial first.
- Stage 1: importing the graphics and setting up the animation groups.
- Stage 2: moving the player's ship:
- Stage 3: spawning the invaders as a swarm:
- Stage 4: moving the invaders.
- Stage 5: firing at the invaders.
- Stage 6: destroying invaders and using particle effects:
- Stage 7: adding some 'snap'.
- Stage 8: adding some 'crackle'.
- Stage 9: adding some 'pop'.
What you learned in this tutorial
- Calculating hash integers from strings once instead of each time they are needed will give you a small performance boost. Algorithms can be computationally expensive, even those with an O(1) time complexity. Any unnecessary code execution should be avoided.
- Lua does not have classic array or list data structures. Instead it uses hash tables, also known as dictionaries or associative arrays. Tables can be indexed with numbers or strings making use of efficient hashing algorithms to find data in the structure.
- References to game objects can be added to a table enabling iteration over many game objects in a script. This is useful when you want game objects to behave both independently and as a group.
- ParticleFX components can be attached to game objects and allow you to create simple particle effects such as explosions, smoke and blood splatters without the need for additional scripts and game objects for the individual particles.