Erel B4X founder Staff member Licensed User Longtime User Sep 27, 2018 #1 This example shows how to use X2TileMap to create a single screen game with tiles based background. This means that the background is never scrolled. To avoid drawing issues we want that the size of each tile will be a whole number and that each tile will be square shaped. This is done with: Code: Copy Dim TileSize As Int = Min(X2.MainBC.mWidth / TileMap.TilesPerRow, X2.MainBC.mHeight / TileMap.TilesPerColumn) TileMap.SetSingleTileDimensionsInBCPixels(TileSize, TileSize) And: Code: Copy Private Sub SetWorldCenter 'The map size will not be identical to the screen size. This happens because the tile size in (bc) pixels needs to be a whole number. 'So we need to update the world center and move the map to the center. X2.UpdateWorldCenter(TileMap.MapAABB.Center) End Sub Drawing a tiles map is done with: Code: Copy Public Sub Tick (GS As X2GameStep) TileMap.DrawScreen(Array("Tile Layer 1"), GS.DrawingTasks) End Sub Public Sub DrawingComplete TileMap.DrawingComplete End Sub The example is included in the examples pack.
This example shows how to use X2TileMap to create a single screen game with tiles based background. This means that the background is never scrolled. To avoid drawing issues we want that the size of each tile will be a whole number and that each tile will be square shaped. This is done with: Code: Copy Dim TileSize As Int = Min(X2.MainBC.mWidth / TileMap.TilesPerRow, X2.MainBC.mHeight / TileMap.TilesPerColumn) TileMap.SetSingleTileDimensionsInBCPixels(TileSize, TileSize) And: Code: Copy Private Sub SetWorldCenter 'The map size will not be identical to the screen size. This happens because the tile size in (bc) pixels needs to be a whole number. 'So we need to update the world center and move the map to the center. X2.UpdateWorldCenter(TileMap.MapAABB.Center) End Sub Drawing a tiles map is done with: Code: Copy Public Sub Tick (GS As X2GameStep) TileMap.DrawScreen(Array("Tile Layer 1"), GS.DrawingTasks) End Sub Public Sub DrawingComplete TileMap.DrawingComplete End Sub The example is included in the examples pack.