DrawMap
DrawMap MapIndex, LevelIndex, Xpos, Ypos
 
Parameters:

    MapIndex = The Index Identifier of the Map you wish to draw a level from.
    LevelIndex = The index of the level you wish to draw.
    Xpos = The X coordinate to draw the level at
    Ypos = The Y coordinate to draw the level at
Returns: NONE
 

     DrawMap will draw a level to current surface (the screen or an image).

      When map levels are drawn, they are treated like huge sprites, with the drawing location being the top left hand coordinate of the level. Just like drawing a large image to the screen, PlayBASIC automatically calculates visible portion of the level and only renders that, anything outside of the screen is ignored.



FACTS:


      * DrawMap automatically handles all clipping when rendering the map to the current surface for you.

      * Certain combinations of the map rendering can be quite slow due to excessive video memory access. For example attempting to render an AFX formatted map to the main screen, forces the render engine to read pixel data over the video bus, which is very slow on the PC. The recommended approach for drawing AFX is to draw the scene to an FX formatted screen sized image, then transfer that to the screen. It's the same rules as image rendering, so we highly recommend reading the images tutorial for the best practices.

      * DrawMap will draw the rects over the blocks when MapDebug is enabled.




Example #1:


      This example creates a map, containing a set of randomly coloured blocks and level. It draws the map at the mouse pointers current position, as if the map was a sprite.


  
; Set Width & Height variables of the Map tiles
  TileWidth=16
  Tileheight=16
  
; Create a map with provision for 5 levels
  MyMap=NewMap(5)
  
; Create some empty graphics blocks for MyMAP
  CreateMapGFX MyMap,TileWidth,TileHeight,11,RGB(0,0,0)
  
  For lp=1 To 10
   ; draw a randomly coloured box to the screen
     BoxC 0,0,TileWidth-1,TileHeight-1,1,RndRGB()
     
   ; Grab a copy the pixels at 0,0, to tilewidth,tileheight
   ; and copy them into this block
     GetMapBlk MyMap, lp, 0,0
  Next
  
  
; Create level 1
  CreateLevel MyMap,1,20,20
  
  
; Start of Do/Loop
  Do
   ; clear the screen to black
     Cls RGB(30,50,20)
     
     
   ; Randomly Fill the level with Tiles
     For Ylp=0 To GetLevelWidth(myMap,1)
        For Xlp=0 To GetLevelWidth(myMap,1)
           PokeLevelTile MyMap,1,Xlp,Ylp,RndRange(1,10)
        Next
     Next
     
     
   ; Draw Level #1 of MyMap to the screen at mouses position
     DrawMap MyMap,1,MouseX(),MouseY()
     
     
   ; Display a Message
     Print "Draw Map Example"
     
   ; Display the screen and loop back to the DO
     Sync
  Loop
  
  





Example #2:


      The attached example is basically the samem except we're now loading a set of grass blocks.





 
Example Source: Download This Example
; Set Width & Height variables of the Map tiles
  TileWidth=32
  Tileheight=32
  
; Create a map with provision for 5 levels
  MyMap=NewMap(5)
  
  
; Load this set of blocks from the MEDIA folder in the help files.
  BlocksFile$="..\../Media/Grass-Tiles.bmp"
  LoadMapGFX BlocksFile$,MyMap,TileWidth,TileHeight,16,RGB(0,0,0)
  
; Create level 1
  CreateLevel MyMap,1,20,20
  
; Randomly Fill the level with Tiles
  For Ylp=0 To GetLevelHeight(myMap,1)
     For Xlp=0 To GetLevelWidth(myMap,1)
        PokeLevelTile MyMap,1,Xlp,Ylp,RndRange(1,15)
     Next
  Next
  
  
  
  
; Start of Do/Loop
  Do
   ; clear the screen to black
     Cls RGB(30,50,20)
     
     
   ; DRaw the Level #1 of MyMap to the screen at mouses position
     DrawMap MyMap,1,MouseX(),MouseY()
     
   ; Display a Message
     Print "Draw Map Example"
     
   ; Display the screen and loop back to the DO
     Sync
  Loop EscKey()=true
  
  
 
Related Info: CreateLevel | CreateMap | LoadMapGfx | Maps | NewLevel | NewMap :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com