Author Topic: One sprite infront of another  (Read 2864 times)


  • Guest
One sprite infront of another
« on: 2007-Feb-18 »
Ahem! well sorry for having to ask this cos i think im missing the glaringly obvious but:-

how do you specify which one of two sprites will be drawn on top of the other when sprites overlap in a 2d game?

LOADSPRITE "man.bmp", 0   
LOADSPRITE "tree.bmp", 1      

SPRITE 0, 100, 100
SPRITE 1, 100, 100

Sometimes i want the man infront of the tree or vice versa.
Its amazing how many example games i`ve looked through that don`t seem to add a "Z" value or something?????
 Thanx in advance, sorry for the dumb question.

Offline Kosta

  • Mr. Polyvector
  • ***
  • Posts: 167
  • nothing.....except 'Kosta'
    • View Profile
    • Kosta's Blog
One sprite infront of another
« Reply #1 on: 2007-Feb-18 »
Hi Phil,

the sprites will be drawn in the order you have written in your script. So if you want to draw a tree in front of all other sprites you have to draw/code the tree last.

for example

sprite 0,100,100   # background sprite
sprite 2,100,100   # main sprite
sprite 1,100,100   # tree in front

-> sprite 0 is behind sprite 2 and 1. sprite 2 is behind sprite 1. sprite 1 is on top.
Intel QuadCore, Geforce8600GT,512MB,4GB Ram, 26" TFT
HP nw8440 Schläppy
GP2X Mk2 (Firmware 3.0)



  • Guest
One sprite infront of another
« Reply #2 on: 2007-Feb-18 »
Thanks for the quick reply Kosta, I've been doing my best like this so far but i cant believe that there is no way to bump a sprite to the front or the middle when its required, I mean it just makes programming something even harder if you have to try n paste bits of code in all over the shop so your sprites are on the correct leyer.

 Anyone else got any ideas or is this just the way it is?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10725
  • here on my island the sea says 'hello'
    • View Profile
One sprite infront of another
« Reply #3 on: 2007-Feb-19 »
Sprites are not real sprites. The name was chosen badly back then. It's more just "blit" or "image". The time you write the SPRITE command, it gets drawn to the back buffer with no idea of layers or whatever.


  • Guest
One sprite infront of another
« Reply #4 on: 2007-Feb-19 »
I see, thanks for the info people. I`ll just have to get the hang of it.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2647
    • View Profile
One sprite infront of another
« Reply #5 on: 2007-Feb-19 »
Create an array that holds all your sprites info (num, x, y, including a Z co-ordinate), then iterate (once you've done all your sprite movement) this array drawing all the sprites of a '0' Z co-ordinate 1st, '1' 2nd, etc... you just need to make your own Z co-ord sprite print routine.


“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)


  • Guest
One sprite infront of another
« Reply #6 on: 2007-Feb-23 »
This looks like the stuff Big Softy, but alas im very new to glbasic, in fact i`m new to all programming, although i`ve made a fair bit of stuff with click team products and some stuff in fenix (but i gave up using fenix cos it was too buggy on the gp2x) so i`ll try and write this idea in to what i`m doing but getting it to work without some kind of example to go off may be above me at this time.
Thanks for helping though, at least i know there is a way.