Time for action — implementing some stars

We can use the following steps to implement some stars:

  1. Create a method in the game class with the name CreateStars. It will have a parameter for the amount of starts to be created.
    Method CreateStars:Int (scount:Int)
    
  2. Start a FOR loop from 1 to the amount of stars to be created.
    For Local i:Int = 1 To scount
    

    Now, create a local star object, which will be a subimage from the texture atlas which we have loaded before. For this, we utilize the CreateImage method of the fantomEngine. At the same time we position it. We could use DeviceWidth and DeviceHeight of Mojo, but fantomEngine can work with virtual canvas sizes so we will use its own canvas size fields.

  3. Create a local star object and position it randomly over the total canvas.
    Local star:ftObject = eng.CreateImage(atlas, 16,112,16,16, Rn(0,eng.canvasWidth),Rnd(0,eng.canvasHeight))
    
  4. Set its scale factor, angle, and also spinning speed.
    star.SetScale(Rnd(1,3)/10)
    star.SetAngle(Rnd(0,359))
    star.SetSpin(5)
    
  5. Now, reset the layer of the star object to layerBackGround. Then close the method.
    star.SetLayer(layerBackGround)
    Next
    Return 0
    End
    

What just happened?

The last method you have implemented will create as many stars on the screen as you have set as its parameter.

The Hero—creating the player ship

Our precious player ship is a little more complex to set up, since you will set up the shield object along with it, as it is a child of the ship.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset