Games [XUI2D] Single Screen Tile Map Example / Hello World With Background

Discussion in 'Game Development' started by Erel, Sep 27, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]

    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:
    Dim TileSize As Int = Min(X2.MainBC.mWidth / TileMap.TilesPerRow, X2.MainBC.mHeight / TileMap.TilesPerColumn)
    TileMap.SetSingleTileDimensionsInBCPixels(TileSize, TileSize)
    And:
    Code:
    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:
    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.
     
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