Games [XUI2D] Beginner question about "TileMap.Initialize"

fredo

Well-Known Member
Licensed User
Longtime User
When comparing the x2 examples it is noticeable that "TileMap.Initialize" is done either at "Sub Initialize" or at "Sub StartGame".

B4X:
Public Sub Initialize (Parent As B4XView) ' HelloWorldWithBackground example
    Parent.LoadLayout("GameLayout")
    world.Initialize("world", world.CreateVec2(0, 0))
    X2.Initialize(Me, ivForeground, world)
    Dim WorldWidth As Float = 10 'meters
    Dim WorldHeight As Float = WorldWidth / 1.333 'same ratio as in the designer script
    X2.ConfigureDimensions(world.CreateVec2(WorldWidth / 2, WorldHeight / 2), WorldWidth)
    'comment to disable debug drawing
    'X2.EnableDebugDraw

    TileMap.Initialize(X2, File.DirAssets, "hello world with background.json", ivBackground)
  
     Dim TileSize As Int = Min(X2.MainBC.mWidth / TileMap.TilesPerRow, X2.MainBC.mHeight / TileMap.TilesPerColumn)
    TileMap.SetSingleTileDimensionsInBCPixels(TileSize, TileSize)
  
    SetWorldCenter
    TileMap.PrepareObjectsDef(ObjectLayer)
    TileMap.CreateObject2(ObjectLayer, 9)
    ...

B4X:
Public Sub StartGame   ' Mario example
    If X2.IsRunning Then Return
    X2.Reset
    X2.UpdateWorldCenter(X2.CreateVec2(X2.ScreenAABB.Width / 2, X2.ScreenAABB.Height / 2))
    GameOverState = False
   
    TileMap.Initialize(X2, File.DirAssets, "mario 1.json", ivBackground)
   
    Dim TileSizeMeters As Float = X2.ScreenAABB.Height / TileMap.TilesPerColumn
    TileMap.SetSingleTileDimensionsInMeters(TileSizeMeters, TileSizeMeters )
    TileMap.PrepareObjectsDef(ObjectLayer)
    TileMap.SetBackgroundColor(0xFF008AFF)

    ...

Is this arbitrary or deliberate with a particular intention?
 
Top