Games [XUI2D] Displaying a Tiled background

ac9ts

Active Member
Licensed User
Longtime User
When I start learning new concepts, I like to take examples and modify them to see how things work. I took HelloWorld_TileMap as a starting point. I wanted to see how to add a tiled background to it. I modified the hello world.json with a simple tile set. It all looks fine when loading it back into Tiled.

In the Game class, I changed
B4X:
TileMap.Initialize(X2, File.DirAssets, "hello world.json", Null)

to

B4X:
TileMap.Initialize(X2, File.DirAssets, "hello world.json", ivGround)

The background is white (the gradient background sub was commented out). I'm not sure if it's the json file or my code. There are no errors displayed in the logs. I must be doing something simple but I can't seem to find it. Code is attached.
 

Attachments

  • BrokenHello.zip
    169.5 KB · Views: 351

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to do two things:
1. Call in Game.Tick:
B4X:
TileMap.DrawScreen(Array("Tile Layer 1"), GS.DrawingTasks)

2. Call in Game.DrawingComplete:
B4X:
Public Sub DrawingComplete
   TileMap.DrawingComplete
End Sub

Examples with tile map background: mario, monster truck and Tiles Map.

I recommend you to start the game development with B4J. The test cycle is faster. You can later add B4A and B4i projects that reference the same modules.
 
Top