Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:15 12 Mar 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMBasic Sprite Z-Order

Author Message
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 568
Posted: 04:26am 12 Mar 2026
Copy link to clipboard 
Print this post

In the SPRITE show command, what good is the layer parameter? No matter what number I put there, the sprites are shown in the reverse order I put them in the buffer with the show statements. The first shown is always at the back, the second is in the middle and the last one shown is always on top. The layer parameter seems to do nothing.
FRAMEBUFFER layer
FRAMEBUFFER write "L"
SPRITE load "balloon.spr"
FOR x=0 TO 280
SPRITE show safe 3,x-15,130,1
SPRITE show safe 2,x,280-x,2
SPRITE show safe 1,x,x,3
FRAMEBUFFER copy L,N
NEXT x

still shows the cyan sprite (#1) on top, the magenta sprite (#2) in the middle and the yellow sprite (#3) at the back, behind the other two. I tried changing the layer numbers around but there was no change in the display of the sprites.
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1421
Posted: 05:19am 12 Mar 2026
Copy link to clipboard 
Print this post

The layer is just one plane that lies above the normal screen. We don't have an infinite number of them here, as that would require infinite Memory.
as I have already explained to you in detail here
Since we don't have a Z-buffer, we have to monitor/determine the order of the images ourselves using sprites. To do this, you must assign a Z value in addition to the x and y values of a sprite.
This has nothing to do with the sprite or the ‘sprite’ command, but determines the order in which the sprites are drawn for your programme.
So you have to make sure yourself that the sprites are drawn in order from far away to very close.
Example:
For Z=-25 To 25
  For n=1 To 20
    If Int(Z1(n))=Z Then
    Sprite write 1,x1(n) , y1(n)
   EndIf
  Next n
Next Z


see this Demo
'no comment
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026