User Tools

Site Tools


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:

      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]
      #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"
      close #g1
      close #g2

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.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
sprites_20in_20multiple_20windows_20_28lbb_29.txt · Last modified: 2018/04/17 19:54 by tbest3112