Web
Analytics
Log In  

0

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 09: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

::

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

::

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

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

::

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

P#54109 2018-07-12 15:12 ( Edited 2018-07-12 15: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 09:56)

Log in to post a comment

user:
password:

New User | Account Help
:: New User
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-07-16 01:12 | 0.211s | 1572k | Q:14