Code layer order
Hello all. I'm having a difficult time figuring out how to keep a sprite on top of the background and other layers. I can keep a sprite visible with just one background but when I try to add a level or platform it disappears completely. I'm trying to make a Mortal Kombat style game so level movement isn't necessary. Any help would be appreciated! Thanks!
I use it like a draw order in my games, so if your background is drawn first any sprite's created after that will layer over.
Past that you have drawsprites() which draws all sprite's in your main loop then to layer them you have drawsprite(player) always best to create them in order at the top in my experience then for the odd one I would use the drawsprite. There is also a setsprite depth but I don't use that.
Last one ...
Maplayers if using maps you can select the layers so when back in the code editor you'll
Have drawmap() drawmaplayer(1)drawsprites()and for foreground drawmaplayer(2).
PB____ last edited by
I think Waldron already answered the question here.
Just in case I'd like to refer to the function setSpriteDepth. With this function you can define in what order the sprites should be drawn amongst other sprites (so which sprites draw on top of other sprites)
But the general idea is indeed that the order in which things are drawn matters. Things that get drawn later, draw over the things that are already there.
setSpriteDepth is very handy and if you're lazy like me, you can cut out a little of the typing by using spritename.depth = x rather than setSpriteDepth(spritename, x)