I hope you can help me out with this one as I have no idea how to approach it.
I have a player character that moves across a screen, and there is an element I am drawing that sometimes should be behind the character and sometimes it should be in front. Basically, if my character is around its area (collided with it) and I press a button, the sprite should come on top of the character. When I press another button, the sprite goes back to being behind the character.
What would be the best way to achieve this, since I cannot dynamically change the order in which things are written? (or can I?) I read some hints at the forum some time ago regarding the use of flags, but I have no idea how this would work (and never used sprite flags before).
Any help appreciated!
Assuming all of the relevant sprites are drawn by iterating through a table of actors or whatever, just make sure you iterate through that table in order (use all or a numeric for loop on indexes to guarantee order). Then you can reorder the actors in that table whenever you need to draw them in a different order.
Easiest way would just be drawing it again if a flag is true. Something like
function _init() infront=false end function _update() if collision and btn(X) then infront=true end if btn(o) then Infront=false end end function _draw() spr(obstacle.sprite,x,y) spr(player.sprite,x,y) if infront then --draw again over player spr(obstacle.sprite,x,y) end end
Kitten's idea would be more token efficient but you can start here then come back to that once you're a leet codaar
Davbo, that's an interesting solution. As the shitty coder that I am, you will realize that I actually am not caring much about things being optimized :P and so far I haven't topped the token limit, so....
I can definitely use kitten's best practice idea once I stop sucking! Thanks to both.
[Please log in to post a comment]