Use the Z value. If you know, how to make it, it's easy.
This engine for 2D games. --> You don't need to remix it. It's a small code. :)