(1) The Tileset .png file is given with "pink" as backgroundcolor to represent transparent pixels
(2) In the tool "Tiled" this is considered automatically.
(3) On the Form the surrogate-color "pink" should be transparent.
What should be done to make the tile backgrounds transparent?
Code used:
(2) In the tool "Tiled" this is considered automatically.
(3) On the Form the surrogate-color "pink" should be transparent.
What should be done to make the tile backgrounds transparent?
Code used:
B4X:
Private Sub GraphicCache_Put_Characters
Log("#-Sub game.GraphicCache_Put_Characters")
Dim bmp As B4XBitmap = xui.LoadBitmap(File.DirAssets, "RPGCharacterSprites32x32.png")
Dim NumberOfSprites As Int = 12
Dim RowWidth As Int = 32
Dim RowHeight As Int = 32
Dim CharHeightMeters As Int = 3
'
Dim RowOfChar1 As Int = 2
Dim character1 As B4XBitmap = bmp.Crop(0, RowHeight * RowOfChar1, NumberOfSprites * RowWidth, RowHeight)
Dim AllChar1 As List = X2.ReadSprites(character1, 1, NumberOfSprites, CharHeightMeters, CharHeightMeters)
X2.GraphicCache.PutGraphic("character1 front walking", Array(AllChar1.Get(0), AllChar1.Get(1), AllChar1.Get(2), AllChar1.Get(3)))
X2.GraphicCache.PutGraphic("character1 front standing", Array(AllChar1.Get(3)))
X2.GraphicCache.PutGraphic("character1 back walking", Array(AllChar1.Get(4), AllChar1.Get(5), AllChar1.Get(6), AllChar1.Get(7)))
X2.GraphicCache.PutGraphic("character1 back standing", Array(AllChar1.Get(7)))
X2.GraphicCache.PutGraphic("character1 side walking", Array(AllChar1.Get(8), AllChar1.Get(9), AllChar1.Get(10)) )
X2.GraphicCache.PutGraphic("character1 side standing", Array(AllChar1.Get(9)) )
'
Dim RowOfChar2 As Int = 3
Dim character2 As B4XBitmap = bmp.Crop(0, RowHeight * RowOfChar2, NumberOfSprites * RowWidth, RowHeight)
Dim AllChar2 As List = X2.ReadSprites(character2, 1, NumberOfSprites, CharHeightMeters, CharHeightMeters)
X2.GraphicCache.PutGraphic("character2 front walking", Array(AllChar2.Get(0), AllChar2.Get(1), AllChar2.Get(2), AllChar2.Get(3)))
X2.GraphicCache.PutGraphic("character2 front standing", Array(AllChar2.Get(3)))
X2.GraphicCache.PutGraphic("character2 back walking", Array(AllChar2.Get(4), AllChar2.Get(5), AllChar2.Get(6), AllChar2.Get(7)))
X2.GraphicCache.PutGraphic("character2 back standing", Array(AllChar2.Get(7)))
X2.GraphicCache.PutGraphic("character2 side walking", Array(AllChar2.Get(8), AllChar2.Get(9), AllChar2.Get(10)) )
X2.GraphicCache.PutGraphic("character2 side standing", Array(AllChar2.Get(9)) )
'
End Sub