Sprites in multiple windows (LBB)
by Richard Russell, February 2015
In LB Booster you can, with care, have sprites in two or more windows or graphicboxes. To make this work you need to take the following steps before every DRAWSPRITES command:
- Re-select the required background bitmap (BACKGROUND command).
- Show all the sprites which 'belong' to this window/graphicbox (SPRITEVISIBLE command).
- Hide all the sprites which do not 'belong' to this window/graphicbox (SPRITEVISIBLE command).
Here is an example of a program which has sprites in two different graphics windows. It uses sprite and background bitmaps from the LB 4.04 examples folder; you should save the program there to ensure it finds the required resources:
nomainwin loadbmp "smiley1", "sprites\smiley1.bmp" loadbmp "crab1", "sprites\crab1.bmp" loadbmp "bg1", "sprites\bg1.bmp" loadbmp "bg2", "sprites\bg2.bmp" open "sprite window 1" for graphics_nsb as #g1 UpperLeftX = 100 open "sprite window 2" for graphics_nsb as #g2 #g1 "trapclose [quit]" #g1 "addsprite smiley1 smiley1" #g1 "spritetravelxy smiley1 200 250 1 [landed]" #g2 "trapclose [quit]" #g2 "addsprite crab1 crab1" #g2 "spritetravelxy crab1 200 250 1 [landed]" timer 40, [animate] wait [animate] #g1 "background bg1" #g1 "spritevisible smiley1 on" #g2 "spritevisible crab1 off" #g1 "drawsprites" #g2 "background bg2" #g1 "spritevisible smiley1 off" #g2 "spritevisible crab1 on" #g2 "drawsprites" wait [quit] close #g1 close #g2 end [landed] wait
Another thing to be aware of is that sprites which are set to move automatically (SPRITEMOVEXY or SPRITETRAVELXY command) will move whenever a DRAWSPRITES command is issued, irrespective of which window or graphicbox the command is sent to. So in the above program they move at twice the speed that might have been expected.
Also, if you use SPRITECOLLIDES it will detect 'collisions' between sprites in different windows or graphicboxes. You may need to ignore sprites which 'belong' to another window yourself.