Tile mapping is a function that takes an image and maps this image into a sequence of scene objects. Each pixel in the map image optionally represents a scene object in the result sequence.
In CosPlay, tile mapping is provided by CPTileMapper object. Here's the code snippet example from Tile Mapping Example that demonstrates the usage of CPTileMapper object:
val tileMapImg = new CPArrayImage( // # - brick // X - player // D - door prepSeq( """ |# # | # | # | # | D | #### |#### | | ## | ## | ## |## | X |########## """), (ch, _, _) => ch&C_BLUE // Does not matter for map. ) // Layout tile sprites. val sprs = CPTileMapper.layout(0, 0, tileMapImg, tileDim = CPDim(10, 10), (ppx, x, y) => ppx.char match case '#' => Option(CPImageSprite(...)) case 'D' => Option(CPImageSprite(...)) case 'X' => Option(CPImageSprite(...)) case _ => None )
NOTES:
10x10
).sprs
) is obtained we should add them to the scene.Here's the screenshot of the tile mapping result from the Tile Mapping Example: