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.

  1. In the assets panel, right click the 'main' folder and select, 'New...', 'Game object'.

New game object

  1. Name the object, 'comet' and click, 'Create Game Object'.
  2. 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'.
      Add sprite
    • In the properties panel, change the 'Image' property to, '/main/graphics.atlas'.
    • In the properties panel, change the 'Default Animation' to, 'comet'.
      Comet
      Remember you can press F and use the mouse wheel to zoom out the editor window if you want.
  3. 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'.
      Add collision object
    • In the properties panel, change the 'Type' property to, 'Kinematic'.
    • In the outline panel, right click, 'collisionobject' and select, 'Add Shape', 'Sphere'.
      Add collision object 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:
    • Comet collision object sphere

We are now ready to create a factory to spawn the comets. Stage 4 >