Log In  

Hi everyone,

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!

P#54104 2018-07-12 13:08 ( Edited 2018-07-13 13:54)

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.

P#54105 2018-07-12 13:30 ( Edited 2018-07-12 17:30)

I don't have a table of actors, I'm a troglodyte coder. :P

This is the only one case where I would need this to happen, though. Hence why I am looking kind of for a one-off approach.

P#54106 2018-07-12 13:39 ( Edited 2018-07-12 17:39)

Easiest way would just be drawing it again if a flag is true. Something like

function _init()

function _update()
 if collision and btn(X) then

 if btn(o) then

function _draw()


 if infront then
  --draw again over player

Kitten's idea would be more token efficient but you can start here then come back to that once you're a leet codaar

P#54107 2018-07-12 14:05 ( Edited 2018-07-12 18:06)

ahaha i literally lol'd XD
that is great. i love it.

P#54109 2018-07-12 15:12 ( Edited 2018-07-12 19:13)

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.

P#54138 2018-07-13 09:54 ( Edited 2018-07-13 13:56)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-03-23 04:22:24 | 0.006s | Q:15