Incoming | Creating the game objects: comet
Comets are different to other game objects because they are spawned during the game and there will be multiple instances of them at any one time. Therefore they require a slightly different approach. Instead of adding them to our main.collection, we will make them independent objects (called blueprints) and use a factory to create instances when they are needed.
A blueprint is essentially the same as a class in object-oriented programming languages.
- In the assets panel, right click the 'main' folder and select, 'New...', 'Game object'.
- Name the object, 'comet' and click, 'Create Game Object'.
- Add the comet animation set to the game object. Try to do this on your own. You can check you followed the right steps by looking at the step-by-step guide.
Step-by-step guide
- In the outline panel, right click 'Game Object' and select, 'Add Component', 'Sprite'.
- In the properties panel, change the 'Image' property to, '/main/graphics.atlas'.
- In the properties panel, change the 'Default Animation' to, 'comet'.
Remember you can press F and use the mouse wheel to zoom out the editor window if you want.
- In the outline panel, right click 'Game Object' and select, 'Add Component', 'Sprite'.
- Add a collision object sphere to the comet.
Step-by-step guide
- In the outline panel, right click, 'Game Object' and select, 'Add Component', 'Collision Object'.
- In the properties panel, change the 'Type' property to, 'Kinematic'.
- In the outline panel, right click, 'collisionobject' and select, 'Add Shape', 'Sphere'.
- Use the editor tools to resize the sphere to match the comet, and the move tool to align the circle over the middle of the comet.
It does not need to be exact. This is about right:
- In the outline panel, right click, 'Game Object' and select, 'Add Component', 'Collision Object'.
We are now ready to create a factory to spawn the comets. Stage 4 >