Games [Soldev] The tiles are not visibled

yves67

Active Member
Licensed User
Longtime 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 ?

thanks
Yves67
 

yves67

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

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

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

yves67

Active Member
Licensed User
Longtime User
Hello,
I have a TileMap.SetSingleTileDimensionsInMeters in my code
I will show you my game.bas :
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)
    Parent.LoadLayout("1")
    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)
    TileMap.PrepareObjectsDef(ObjectLayer)
    Dim ol As X2ObjectsLayer = TileMap.Layers.Get(ObjectLayer)
    For Each template As X2TileObjectTemplate In ol.ObjectsById.Values
        Dim bw As X2BodyWrapper = TileMap.CreateObject(template)
    Next
'    X2.SetBitmapWithFitOrFill(ivBackground, xui.LoadBitmapResize(File.DirAssets, "Sky.jpg", ivBackground.Width / 2, ivBackground.Height / 2, False))
    X2.Start
End Sub

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

Public Sub DrawingComplete
    TileMap.DrawingComplete()
End Sub
 

yves67

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

yves67

Active Member
Licensed User
Longtime 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
and
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
 
Top