Tilemaps are a 2-dimensional grid of bytes, where each entry points to an Entry of a TileSet
In the Display Layers, You get access to two TileMaps out of the Box.
The Maps default Size is 32x32 tiles. You probably want to adjust that, depending on your chosen resolution and the size of the TileSet you plan to use. (See Engine-Setup for more info on how to change the Maps size)
Before you can enable any of the two Build in Maps, you must first define a TileSet, that your chosen layer will use
The following would need to happen during your Scenen Load-Lifecycle-Hook
func (me *ExampleScene) Load(state *core.EngineState, canvas *core.Canvas) {
var tileSet := core.TileSet{}
tileSet.InitFromMapSheet(
/* your core.Bitmap */,
/* PixelWidth of each Tile */,
/* PixelHeight of each Tile */,
);
// ...
with That, you can then enable your chosen Map-Layer through the Engine State
// ...
state.EnableMap1Layer(&tileSet)
// ...
And Start filling it with Data
//...
state.Map1.SetMap([]byte{ /* your Maps Tile definitions goes here */ })
}
func (tm *TileMap) Init(tileSet *core.TileSet, width, height uint32) *TileMap
Warning
using this method on the Build In Maps, will cause GO to panic.
If you don't use the Build In Maps, you MUST initialize your Maps first. see Creating your own TileMaps for more details.
Parameter | Type | Description |
---|---|---|
ts |
*core.TileSet |
The catalogue from which the map will define, how to draw each tile. Must not have more than 255 Tiles |
width |
uint32 | Numer of tiles on the x axis |
height |
uint32 | Numer of tiles on the y axis |
*core.TileMap
The Tilemap, on which that Method was executed.
(That way, you can chain multiple Setter Functions together)
func (*TileMap) SetMap (tiles []byte) *TileMap
Redefines all Tiles in the Map
Parameter | Type | Description |
---|---|---|
tiles |
[]byte |
A slice of bytes containing the new Map definition |
Tiles are updated from left to right first and top to bottom second. So in a 6x3 Tilemap, the Bytes would be assigned as follows
------------------------------------------------------------------------------------
| tiles[0] | tiles[1] | tiles[2] | tiles[3] | tiles[4] | tiles[5] |
------------------------------------------------------------------------------------
| tiles[6] | tiles[7] | tiles[8] | tiles[9] | tiles[10] | tiles[11] |
------------------------------------------------------------------------------------
| tiles[12] | tiles[13] | tiles[14] | tiles[15] | tiles[16] | tiles[17] |
------------------------------------------------------------------------------------
Warning
How many Bytes the given Slice must contain depends either on width
* height
given during the Maps Init call
or, if you use the Build In Maps the TileMapWith
* TileMapHeight
given during the Engine Setup
*core.TileMap
The Tilemap, on which that Method was executed
(That way, you can chain multiple Setter Functions together)
func (me *TileMap) SetTileSet(ts *TileSet) *TileMap
Allows for changing the Maps TileSet after the Map was Initialized.
Note
If a Tiles Tile-Pixel-Size changes the overall displayed pixel-Size of the map will change with it
Parameter | Type | Description |
---|---|---|
ts |
*core.TileSet |
The catalogue from which the map will define, how to draw each tile. Must not have more than 255 Tiles |
*core.TileMap
The Tilemap, on which that Method was executed
(That way, you can chain multiple Setter Functions together)
func (me *TileMap) Clear(tileIndex byte) *TileMap
Resets all Tiles in the Map back to 0
*core.TileMap
The Tilemap, on which that Method was executed
(That way, you can chain multiple Setter Functions together)
func (me *TileMap) SetTile(x, y uint32, tile byte) *TileMap
Changes what Tile is displayed at coordinates x, y
Parameter | Type | Description |
---|---|---|
x |
uint32 |
The Tiles X coordinate in the Map |
y |
uint32 |
The Tiles Y coordinate in the Map |
tile |
byte |
The new Tiles index inside the TileSet |
*core.TileMap
The Tilemap, on which that Method was executed
(That way, you can chain multiple Setter Functions together)
func (me *TileMap) AlphaSet(a CanvasAlpha) *TileMap {
(see: Alpha-Blending => AlphaSet)
*core.TileMap
The Tilemap, on which that Method was executed
(That way, you can chain multiple Setter Functions together)
func (me *TileMap) AlphaReset() *TileMap {
(see: Alpha-Blending => AlphaReset)
*core.TileMap
The Tilemap, on which that Method was executed
(That way, you can chain multiple Setter Functions together)
func (me *TileMap) ScrollTo(x, y int32) *TileMap
Offsets the visible area of the map by x
and y
pixels.
Parameter | Type | Description |
---|---|---|
x |
int32 |
Absolute horizontal offset starting from the left of the Map |
y |
int32 |
Absolute vertical offset starting from the top of the map |
[!info]
Should the Viewport area reach the Map Borders, the Map will wrap around, to fill the Screen.
*core.TileMap
The Tilemap, on which that Method was executed
(That way, you can chain multiple Setter Functions together)
func (me *TileMap) ScrollBy(x, y int32) *TileMap
It works as ScrollTo does, but the x
and y
values are relative to the current scroll-offset of the Map
Parameter | Type | Description |
---|---|---|
x |
int32 |
relative horizontal offset from the current scroll-x coordinate |
y |
int32 |
relative vertical offset from the current scroll-y coordinate |
*core.TileMap
The Tilemap, on which that Method was executed
(That way, you can chain multiple Setter Functions together)
func (me *TileMap) Alpha() CanvasAlpha
CanvasAlpha
the current Alpha-Level of the Map
func (me *TileMap) HasTileSet() bool
true
== the Maps has a Tileset, it can render from.
(use SetTileSet(nil)
to deactivate the current aktive tileset)
func (me *TileMap) X() int32
The current horizontal Scroll of the Map
func (me *TileMap) Y() int32 { return me.opts.Y }
The current vertical Scroll of the Map
func (me *TileMap) XY() (int32, int32) { return me.opts.X, me.opts.Y }
The current horizontal and vertical Scroll of the Map
func (me *TileMap) ToCanvas(ca *core.Canvas)
Renders the Map onto the given core.Canvas
Parameter | Type | Description |
---|---|---|
ca |
core.Canvas |
the target canvase onto which to render the Map |
If you don't want to remain bound to the 2 Layers, that GoWas comes with, you can also define your own maps, that can be rendered on the Scene.Draw Layer during your Scenes Draw-Lifecycle-hook
To do so, you first must define where your Map will live inside your applications.
myMap := core.TileMap{}
//...
Then you must initialize it. For this, you can use The Maps Init
-Method
//...
myMap.Init(*someTileset, 10, 10)
//...