Hello,
I am trying to understand how tilemaps work in order to design a tiny tilemap engine like the retro video display processors. I decided to start from the amazing Pacdroid, and I understood how the tilemaps work: get and put tiles, layers etc. Very cool library.
Now I want to understand if i can color remap individual tiles. Here's the practical example... I have a screen like the retrocomputers screens, made of 32 by 24 8x8 pixel tiles. I want to print a text using the tiles ordered by the ASCII characters index, let's say something like:
The routine is something that set the X and Y tile starting position, then a cycle that gets the char code of each character in the string, then gets the corresponding tile ( space: 32, H: 72 etc... ). And it works and it's incredibly fast. This library is cool.
Now what if I want to change the color of the tiles? For example if I want to change the text color:
At this point If there is a way to remap the color of the tile it would be good, but I will change also the color of the background pixels. So I should use a tileset with the alpha channel so that I will remap only the "foreground" color. So I used a png image imported in Tiled and saved as a tmx. Now the map is loaded, and the layer is shown correctly with the correct transparency, but if I try to change a tile on the layer the program crashes.
The tilemap is initialised in the "clsMaze" class like Pacdroid does:
And the code that change a tile on the layer is:
Where Maze.Tiles is an array of
Everything works if I use a tileset derived from a bmp image, but it crashes when I use a png. Is there an issue or I should use another way to do this? I hope I have been clear in my explainantion.
Thanks.
I am trying to understand how tilemaps work in order to design a tiny tilemap engine like the retro video display processors. I decided to start from the amazing Pacdroid, and I understood how the tilemaps work: get and put tiles, layers etc. Very cool library.
Now I want to understand if i can color remap individual tiles. Here's the practical example... I have a screen like the retrocomputers screens, made of 32 by 24 8x8 pixel tiles. I want to print a text using the tiles ordered by the ASCII characters index, let's say something like:
B4X:
PRINT AT 10,10 "HELLO WORLD!"
The routine is something that set the X and Y tile starting position, then a cycle that gets the char code of each character in the string, then gets the corresponding tile ( space: 32, H: 72 etc... ). And it works and it's incredibly fast. This library is cool.
Now what if I want to change the color of the tiles? For example if I want to change the text color:
B4X:
COLOR RED: PRINT AT 10,10 "HELLO WORLD!"
At this point If there is a way to remap the color of the tile it would be good, but I will change also the color of the background pixels. So I should use a tileset with the alpha channel so that I will remap only the "foreground" color. So I used a png image imported in Tiled and saved as a tmx. Now the map is loaded, and the layer is shown correctly with the correct transparency, but if I try to change a tile on the layer the program crashes.
The tilemap is initialised in the "clsMaze" class like Pacdroid does:
B4X:
Sub Class_Globals
Private Maps As lgMapTiledMap
Private MapRenderer As lgMapOrthogonalTiledMapRenderer
Dim CurrentLayer As lgMapTiledMapLayer
Dim MapWidth, MapHeight As Int 'in tiles
Dim TileSize As Float 'in pixels
Dim TotalTiles As Int = (256)
Dim Tiles(TotalTiles) As lgMapStaticTiledMapTile
End Sub
'Loads the mazes and initializes the map renderer
Public Sub Initialize(Width As Int, Height As Int, GutterSize As Float, SpriteBatch As lgSpriteBatch)
'Loads the mazes (TMX format)
LoadMazes
'Initializes the map renderer and computes the tile size
MapWidth = Maps.Properties.Get("width")
MapHeight = Maps.Properties.Get("height")
Dim TileWidth As Int = Maps.Properties.Get("tilewidth")
Dim TileHeight As Int = Maps.Properties.Get("tileheight")
Dim RatioW As Float = Width / (TileWidth * MapWidth)
Dim RatioH As Float = (Height - (GutterSize * 2)) / (TileHeight * MapHeight)
If RatioW < RatioH Then
MapRenderer.Initialize4(Maps, RatioW, SpriteBatch)
TileSize = MapRenderer.UnitScale * TileWidth
Else
MapRenderer.Initialize4(Maps, RatioH, SpriteBatch)
TileSize = MapRenderer.UnitScale * TileHeight
End If
'Selects the default layer
SelectLayer(0)
'Gets the reference tiles
GetRefTiles
End Sub
Private Sub LoadMazes
'Loads the mazes (TMX format)
Dim TMXLoader As lgMapTmxMapLoader
Maps = TMXLoader.Initialize2("maps/Ardisplay.tmx")
End Sub
And the code that change a tile on the layer is:
B4X:
Sub LG_Update
...
Dim TileX, TileY, NumTile As Int = 0
Maze.CurrentLayer.GetCell(TileX, TileY).Tile = Maze.Tiles(NumTile)
...
End Sub
Where Maze.Tiles is an array of
B4X:
Dim TotalTiles As Int = (256)
Dim Tiles(TotalTiles) As lgMapStaticTiledMapTile
Everything works if I use a tileset derived from a bmp image, but it crashes when I use a png. Is there an issue or I should use another way to do this? I hope I have been clear in my explainantion.
Thanks.