PeekLevelTile
TileIndex = PeekLevelTile(MapIndex, LevelIndex, TileXpos, TileYpos, [ResolveAnim=false])
 
Parameters:

    MapIndex = The Index Identifier of the Map you wish to query a level within.
    LevelIndex = The index of the level you wish to query.
    TileXpos = The X coordinate in the level map
    TileYpos = The Y coordinate in the level map
    [ResolveAnim=false] = Optional parameter that forces the command to return a current tile within a animation, if peeking an animation.
Returns:

    TileIndex = This will be either a Tile Index or Animation Index
 

      PeekLevelTile lets us read tiles directly from a level.

      Note: When reading information from a level map, two types of data can be returned. It could be either a Tile Index or Tile animation Index. You can distinguishe between them by analyzing the values returned. Animations indexes will be 'negative', as when these values are poked into the level, they have the high bit set (bit 31).


      I.e. This code will distinguish between a Tile Index and an Tile animation Index

  
  ThisTile = PeekLevelTile(ThisMap,ThisLevel,TileXpos,TileYpos)
  
  If ThisTile & pbmapanim_mask
     AnimIndex= (ThisTile And $ffff)
     Print "This is an Animation index:"+Str$(animIndex)
  Else
     Print "This is a Tile Index:"+Str$(ThisTile)
  EndIf
  





FACTS:


      * Tile Indexes will range between 0 and 4096

      * Tile Animation indexes will be returned as negative numbers. As values have their high bit set (bit 31 See PBMapAnim_Mask). you an convert them back to Animation Index by masking (Anding) off the high bit and keeping the lower bits ie. AnimIndex = Value and $ffff.

      * The TileXpos parameter is in TILES not pixels.

      * The TileYpos parameter is in TILES not pixels.




Mini Tutorial:


      This example creates a map with tile graphics and a level map the size of the display. The user can draw tiles onto the blank map by Poking them with the mouse as well and examining by hovering the mouse over them.


  
; Set Width & Height variables of the Map tiles
  TileWidth=32
  Tileheight=32
  
; Create a map with provision for 5 levels
  MyMap=NewMap(5)
  
; Create some empty graphics blocks for MyMAP
  CreateMapGFX MyMap,TileWidth,TileHeight,2,RGB(0,0,0)
  
; draw a Green Box
  BoxC 0,0,TileWidth,TileHeight,1,RGB(0,255,0)
  
; Copy the green box to MyMap as Tile #1
  GetMapBlk MyMap, 10,0
  
  
; Create level 1
  CreateLevel MyMap,1,100,100
  
  
; Start of Do/Loop
  Do
   ; clear the screen to black
     Cls RGB(0,0,0)
     
   ; Calculate the Tile coords the mouse is currently over
     TileX=MouseX()/TileWidth
     TileY=MouseY()/TileHeight
     
   ;  Check if the mouse button is pressed then
   ; poke this Tile with a Tile #1..
     If MouseButton()
        PokeLevelTile MyMap,1,TileX,TileY,1
     EndIf
     
     
   ; Draw Level #1 of MyMap to the screen at xpos 0, Ypos 0
     DrawMap MyMap,1,0,0
     
     
   ; Read This Tile Back.
     Print "Press Mouse Button to Draw Tile"
     Print "Current Tile Number Under Mouse:"+Str$(PeekLevelTile(MyMap,1,TileX,TileY))
     
     
   ; Display the screen and loop back to the DO
     Sync
  Loop
  
  



This example would output.

  
  no output.
  

 
Related Info: LevelAnimated | LevelDrawMode | LevelSolid | LevelTransparent | PBMapAnim_Mask | PokeLevelTile :
 


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