   sync on : sync rate 0
   disable escapekey

` If it is needed, reinitialize the plugin.
   if screen width() <> 640 or screen height() <> 480 then set display mode 640,480,32 : dxs initialize


` Create a sprite that will display a background.
   backgroundSprite = dxs create sprite("AdvancedSPRITES.png")

` Cut it into 3072 tiles of 10x10 pixels : 64x48 tileset size.
` The test will be done on this number of sprites displayed.
   dxs set sprite tileset backgroundSprite,64,48

` Create the same sprite than above using default DBPro commands.
   create animated sprite 1,"AdvancedSPRITES.png",64,48,1

` First, the render is done with DBPro.
   render$ = "DBPro Sprites"


` Repeat until the user press the escape key.
   repeat

   ` Clear the screen, needed.
      cls

   ` A click change the render mode.
      if mouseclick() > 0
         if render$ = "DBPro Sprites" and key = 0 then render$ = "AdvancedSPRITES" : key = 1
         if render$ = "AdvancedSPRITES" and key = 0 then render$ = "DBPro Sprites" : key = 1
         inc key
      else
         key = 0
      endif


      if render$ = "AdvancedSPRITES"

      ` Render with AdvancedSPRITES.
         dxs begin sprite render backgroundSprite
            for ty = 0 to 48
               for tx = 0 to 64
                  dxs draw sprite tile backgroundSprite,1 + ty * 64 + tx,tx * 10,ty * 10
               next tx
            next ty
         dxs end sprite render backgroundSprite

      else

      ` Render with DBPro default sprites.
      ` This method (create animated sprite + set sprite frame + paste sprite) is the fastest
      ` way I know to draw a tileset with DBPro.
         for ty = 0 to 48
            for tx = 0 to 64
               set sprite frame 1,1 + ty * 64 + tx
               paste sprite 1,tx * 10,ty * 10
            next tx
         next ty

      endif

   ` Indicates render mode and framerate.
      text 10,10,"Currently rendering 3072 sprites using " + render$ + ", click to switch."
      text 10,30,"FPS : " + str$(screen fps())

      sync

   until escapekey() = 1


` Delete resources when the test ended.
   dxs delete sprite backgroundSprite
   delete image 1 : delete sprite 1

   end
