Games [Soldev] The tiles are not visibled


Active Member
Licensed User
I start a simple new game
and in the Tile layer 1 I have several tiles to draw my scene
but when I run the game, no tiles are displayed
is something to do like TileMap.Dranscreen ?
I try but get an error (division by zero)

in the json file, the tiles are in the data field ?



Active Member
Licensed User
After searching in the forum I have found the solution to display the tile layer :
it is :

I put this code in my game.bas, but now I have an error :

I look at my code, but I have no idea why I have this error
thanks for anyhelp
Regards Yves67


Active Member
Licensed User
I have a TileMap.SetSingleTileDimensionsInMeters in my code
I will show you my game.bas :
#if B4A
'ignore DIP related warnings as they are not relevant when working with BitmapCreator.
#IgnoreWarnings: 6
#end if
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
Sub Class_Globals
    Public X2 As X2Utils
    Private xui As XUI 'ignore
    Public world As B2World
    Public Ground As X2BodyWrapper
    Private ivForeground As B4XView
    Private ivBackground As B4XView
    Public lblStats As B4XView
    Public TileMap As X2TileMap
    Public Const ObjectLayer As String = "Object Layer 1"
    Public RightDown, LeftDown, JumpDown, DownDown, UpDown As Boolean
End Sub

Public Sub Initialize (Parent As B4XView)
    world.Initialize("world", world.CreateVec2(0, -20))
    X2.Initialize(Me, ivForeground, world)
    Dim WorldHeight As Float = 14 'the size of each tile will be approximately 1x1 meter
    Dim WorldWidth As Float = WorldHeight * 1.3333
    X2.ConfigureDimensions(world.CreateVec2(WorldWidth / 2, WorldHeight / 2), WorldWidth)
    lblStats.TextColor = xui.Color_Black
    lblStats.Color = 0x88ffffff
    lblStats.Font = xui.CreateDefaultBoldFont(20)
    'comment to disable debug drawing
    ' X2.EnableDebugDraw
    TileMap.Initialize(X2, File.DirAssets, "test.json", Null)
    TileMap.SetSingleTileDimensionsInMeters(WorldWidth / TileMap.TilesPerRow, WorldHeight / TileMap.TilesPerColumn)
    Dim ol As X2ObjectsLayer = TileMap.Layers.Get(ObjectLayer)
    For Each template As X2TileObjectTemplate In ol.ObjectsById.Values
        Dim bw As X2BodyWrapper = TileMap.CreateObject(template)
'    X2.SetBitmapWithFitOrFill(ivBackground, xui.LoadBitmapResize(File.DirAssets, "Sky.jpg", ivBackground.Width / 2, ivBackground.Height / 2, False))
End Sub

Public Sub Tick (GS As X2GameStep)
    TileMap.DrawScreen(Array("Tile Layer 1"),GS.DrawingTasks)
End Sub

Public Sub DrawingComplete
End Sub


Active Member
Licensed User
looking in the Mario sample, I have no StartGame subroutine, I start from the tank example
should I have a StartGame subroutine ?


Active Member
Licensed User
ok, I have added a StartGame subroutine and look at the code in Mario
I still had the error, but looking more carrefully I saw a difference in the following line :
TileMap.Initialize(X2, File.DirAssets, "test.json", Null) coming from the tank example
TileMap.Initialize(X2, File.DirAssets, "test.json", ivBackground) coming from Mario

Now no more error I am able to load the tile layer and start the game correctly