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

Discussion in 'Game Development' started by fredo, Jul 19, 2019.

  1. fredo

    fredo Active Member Licensed User

    When comparing the x2 examples it is noticeable that "TileMap.Initialize" is done either at "Sub Initialize" or at "Sub StartGame".

    Code:
    Public Sub Initialize (Parent As B4XView) ' HelloWorldWithBackground example
        Parent.LoadLayout("GameLayout")
        world.Initialize(
    "world", world.CreateVec2(00))
        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)
        ...
    Code:
    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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    There is no particular reasoning behind it. Both options are good.
     
    fredo likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice