Little layer problem when shooting


(Froom7) #1

Heya fellow developers,

I have this little problem when I want to shoot a “beam”. The beam goes in front of the UFO. How do I get it behind the ship? Here is an image from it below. I’d assume it’s an pretty easy problem, but much help is appreciated :smile:


(Justin Wolf) #2

All entities use a layer property. Assuming your UFO and beam are separate entities, simply set the layer of your UFO to one that is less than the layer of your beam in the constructor. E.g: UFO’s layer would be -1, beam’s layer would be 0. So long as the layer of the UFO is less than the beam’s, it will always appear in front of any newly created beams.

UFO’s Entity class

public class UFO extends Entity
{
     public function UFO()
     {
          layer = -1;
          // other constructor code here
     }
}

Beam’s Entity class

public class Beam extends Entity
{
     public function Beam()
     {
          layer = 0;
          // other constructor code here
     }
}

(Froom7) #3

Ah right, got it. That did it. Maybe I should take some time to go through the docs… Well, you’ll miss the little things when you’re programming in the middle of the night… Thx for the answer!