Category: 2D Overlay
Syntax:
b2dLoadIndexedImage:Int(filePath:String)
Int
Loads an 8-bit indexed (palette) PNG and returns an image handle.
Takes filePath (the file to load).
Returns an image handle (a positive integer), or 0 on failure.
The image's pixels are palette INDICES rather than colours, which is what makes palette animation possible: rotating the palette entries animates the picture with no per-pixel work at all. Draw it with b2dDrawImage exactly like any other image.
The file must genuinely be indexed. A truecolour PNG is rejected rather than silently converted, and the reason is printed. Only single-frame images are supported - there is no indexed animation-sheet loader.
Indexed images take their colour entirely from the palette, so b2dSetColor does NOT tint them - tinting would fight the cycling. b2dSetAlpha does still apply.
View detailed documentation online
Local img:Int = b2dLoadIndexedImage("water.png")
If img = 0 Then
Print "Could not load - is it an 8-bit indexed PNG?"
Return 1
EndIf
b2dCyclePalette(img, 16, 31, 8.0) ; 16 entries, 8 per second
While sysQuitRequested() = 0
sysUpdateEvents()
b2dCls()
b2dDrawImage(img, 0, 0)
b2dFlip()
Wend
BambooBasic © 2026 Michael Denathorn