![]() |
Forum Index : Microcontroller and PC projects : Sprite feature suggestion/request
Author | Message | ||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
Sprites would be easier and faster to use if you didn't have to make a loop to erase and redraw them in order to make changes behind them. MMBasic already provides the ability to do the erasing and redrawing itself for SPRITE SCROLL and SPRITE MOVE, but we don't have full access to this feature. So we can't use it to print behind sprites, or copy a background page behind sprites, or display something new when the screen is scrolled behind sprites. I can think of two ways to improve this. 1 - specifically have a command like page copy, but it copies graphics behind sprites. It could be a sub command of SPRITE, BLIT, or PAGE. 2 - have a SPRITE command to temporarily hide the sprites, and they get redrawn when you do SPRITE MOVE, or some other chosen command (SPRITE RESTORE?) Command name ideas I had: SPRITE MOVE OFF. SPRITE MOVE HIDE. SPRITE SHOW OFF. Or maybe something starting with SPRITE HIDE. The second way is more flexible, because in the time between hiding and restoring the sprites, you could use any graphics commands you want to modify the background page. PRINT, CIRCLE, PAGE COPY, BLIT. So you could do something like this: SPRITE HIDE PRINT "Hello from behind the sprites" SPRITE RESTORE The temporarily hidden sprites would be in a pending state until they are restored. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10062 |
Nice idea ![]() Try the attached: SPRITE HIDE ALL will remove all sprites SPRITE RESTORE will replace them I hope ![]() CMM2V1.5 (2).zip Note if this works I need to do some more work to trap SPRITE command that mustn't be used when HIDE ALL is active Edited 2020-08-22 20:59 by matherp |
||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
That was quick! USB keyboard's not fully working - it works in the editor but not on the command line, so I need to use the terminal connection. The new commands work though. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10062 |
Oops - sorry ![]() CMM2V5.05.05b18exp.zip |
||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
Thanks. I have another suggestion/request. I don't know of an easy way to hide a sprite during a SPRITE MOVE. It could be either SPRITE NEXT spr,x,y, if you allow the coordinates to move it completely offscreen, or a new subcommand like SPRITE NEXT HIDE. Or an alternative would be enabling switching off individual sprites during a SPRITE HIDE ALL, so they don't come back on at the end. That works, thanks. I made a demo with the new commands (flickering a bit because I haven't used double buffering). MODE 1,8 CLS RBOX 10,10,20,20,3,RGB(WHITE),RGB(MAGENTA) SPRITE READ 1,10,10,20,20,0 SPRITE READ 2,10,10,20,20,0 SPRITE READ 3,10,10,20,20,0 bg=RGB(CYAN) CLS bg y=200 SPRITE SHOW 1,10,y,0,0 SPRITE SHOW 3,10,y,0,0 x=11 do x=(x+3) mod 600 pause 50 SPRITE NEXT 1,x,y SPRITE NEXT 3,x,y+x/2 SPRITE MOVE SPRITE SHOW 2,700-x,y+50,0 r=RND*255 g=RND*255 b=RND*255 SPRITE HIDE ALL CIRCLE RND*800, RND*600, RND*100,,,0, RGB(r,g,b) PAGE SCROLL 0,1,1 SPRITE RESTORE loop Edited 2020-08-22 22:45 by capsikin |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10062 |
If I've got it right you can use SPRITE NEXT either before or during the HIDE and the RESTORE will put the sprites in the new position and trigger the collision detection |
||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
If I've got it right you can use SPRITE NEXT either before or during the HIDE and the RESTORE will put the sprites in the new position and trigger the collision detection I don't think that's it. What I mean is, I've got a sprite displaying and want to remove it. I don't want to just SPRITE HIDE 1 in case there's another sprite in front of it. SPRITE NEXT can only put it somewhere else on the screen, not right off screen. Good to know I can use SPRITE NEXT before/during a SPRITE HIDE ALL though. If you plan to allow SPRITE HIDE 1 during a SPRITE HIDE ALL that might do what I want. |
||||
JoOngle Regular Member ![]() Joined: 25/07/2020 Location: SwedenPosts: 82 |
IMHO sprites should be non-destructive aka not interfere with the background (or any foreground) graphics at all. Hide and restore is a needed function, but to use it to allow other changes to happen to the screen is sorta cheating and will make games horribly slow when this could all be done in the OS itself. (not a critique, thanks for your amazing work Peter), it's just an observation (not to mention, perhaps wishful thinking here), but then again I come from a background where sprites where real sprites, aka totally independent of the background graphics, like miniature screens if you like. Even the arcade machines had these sprites often referred to as "player / missile" objects. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10062 |
OK Try this. SPRITE HIDE SAFE n This will remove a sprite irrespective of if other sprites are on top of it. It is of course much less efficient than using a simple hide if you know the sprite isn't covered CMM2V1.5.zip box 0,0,50,50,4,rgb(red),rgb(white) sprite read 1,0,0,50,50 sprite copy 1,2,2 sprite show 1, 150,150,1 sprite show 2, 170,170,1 sprite show 3, 190,190,1 pause 2000 sprite hide safe 2 pause 2000 sprite hide safe 1 pause 2000 sprite show 1, 150,150,1 pause 2000 sprite hide safe 3 do loop |
||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
SPRITE HIDE SAFE n This will remove a sprite irrespective of if other sprites are on top of it. It is of course much less efficient than using a simple hide if you know the sprite isn't covered CMM2V1.5.zip box 0,0,50,50,4,rgb(red),rgb(white) sprite read 1,0,0,50,50 sprite copy 1,2,2 sprite show 1, 150,150,1 sprite show 2, 170,170,1 sprite show 3, 190,190,1 pause 2000 sprite hide safe 2 pause 2000 sprite hide safe 1 pause 2000 sprite show 1, 150,150,1 pause 2000 sprite hide safe 3 do loop Thanks, I'll test that tomorrow. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10062 |
Even better ![]() SPRITE SHOW SAFE n, x, y, layer CMM2V1.5.zip box 0,0,50,50,4,rgb(red),rgb(white) box 0,50,50,50,4,rgb(green),rgb(yellow) sprite read 1,0,0,50,50 sprite read 2,0,50,50,50 sprite show 1, 150,150,1 sprite show 2, 170,170,1 pause 2000 sprite show safe 1,180,180,1 pause 2000 sprite show safe 2,190,190,1 pause 2000 sprite show safe 1,200,200,1 pause 2000 sprite hide safe 3 do loop |
||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
you can use SPRITE NEXT either before or during the HIDE and the RESTORE will put the sprites in the new position This is good, it's something I hadn't thought of initially - not having to have separate erase/redraw loops for moving the sprites with SPRITE NEXT and for changing the background with SPRITE HIDE ALL / SPRITE RESTORE ![]() SPRITE SHOW SAFE n, x, y, layer CMM2V1.5.zip Thanks! I tried both the test programs you gave, using this later firmware. They worked correctly. I removed the "SAFE" and tried again, and got screen corruption as expected. Standalone commands like this will be easy for people to use, which is good. I was initially thinking of something I could bundle with other commands though, and only need one erase/redraw for all of them when I do SPRITE MOVE or SPRITE HIDE ALL, for efficiency. I have thought of ways I can work around it though, by limiting how many SPRITE HIDE SAFE commands I try to do at once, and/or by moving the sprites into the corner so they only have one pixel on screen, and make it a transparent pixel. I've replied to this on the other thread. Edited 2020-08-23 14:32 by capsikin |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |