|
Forum Index : Microcontroller and PC projects : MMBasic Sprite Z-Order
| Author | Message | ||||
| toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 602 |
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: GermanyPosts: 1447 |
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 |
||||
| thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4367 |
I think Martin may be "mixing it up" by "misunderstanding" something to do with 'Mite graphics .The "L" buffer and the "layer" parameter to SPRITE SHOW are orthogonal concepts and "L" is at best loosely related to sprite Z-order and "layer" completely unrelated. The ONLY THING that the "layer" parameter does is control collision detection. Sprites can only collide with other sprites on the same layer OR sprites on layer 0. With the "L" buffer anything (not just sprites) drawn on the "L" buffer will be on-top when it is merged with the "F" buffer to populate the "N" buffer/display. With regards Z-order: - When a sprite is shown it is pushed onto a stack. Sprites lower on the stack are "beneath" those higher on the stack. - To manually move a sprite without artifacts caused by other sprites "above" it at the same position you have to HIDE (pop) every sprite higher up the stack, move the sprite in question and then SHOW (push) back all the sprites you hid. SPRITE SHOW SAFE does this stack manipulation for a single sprite automatically. - For performance when moving multiple sprites you should use SPRITE NEXT to set new positions for all your sprites and then a single call to SPRITE MOVE to actually perform the movement. (At least on MMB4L) this is done by iterating down the stack hiding each sprite at its original position, updating all the sprite positions and then iterating up the stack showing each sprite in its new position. - The only way you can change the Z-order of a sprite is to hide it and then re-show it on top. You can do this safely with the "ontop" parameter to SPRITE SHOW SAFE. Also note that from Martin's example SPRITE WRITE is in my opinion "not a sprite command at all". It's a holdover from when PicoMite BLIT and SPRITE were synonyms. All it does is "stamp" a copy of the sprite's image on the current write surface with no other interaction with the sprite system. Hope this helps, and Peter doesn't tell me it is complete twaddle .Best wishes, Tom Edited 2026-03-12 19:48 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
| toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 602 |
Please see my other post on this topic. NEXT and MOVE don't seem to work on my system unless I'm missing something. FRAMEBUFFER layer FRAMEBUFFER write "L" SPRITE load "balloon.spr" FOR x=0 TO 280 SPRITE next 3,1,x-5,140 SPRITE next 2,x,280-x SPRITE next 1,x,x SPRINT move FRAMEBUFFER copy L,N NEXT x Edited 2026-03-12 20:33 by toml_12953 |
||||
| thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4367 |
You were missing something, see original post. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |