Skip to content

Cs2dMapArray

Magnus edited this page Nov 29, 2017 · 1 revision

The Cs2dMapArray Object

The Cs2dMapArray object allows modification of the whole map and its tiles, changing things like frames and tile modes like color

to change the frame of a tile do

tile(int x, int y) to get the tile, then change it using .setFrame(int frame)

example: cs2dMapArray.tile(10,10).setFrame(24);

the map can be resized to any size using cs2dMapArray.resizeMap(50,50)

theres a few methods like fill(TileAction tileAction) and rectangle(int x1, int y1, int x2, int y2, TileAction tileAction) and circle(int x1, int y1, int x2, int y2, TileAction tileAction) that do exactly what you might expect

alot of methods take in a thing called TileAction, this interface simply says what to do with each tile and can either be implemented manually or you can simply have a few pre-made TileAction's from the TileActions object (static)

  • TileActions.setFrame(int frame) changes the frame of a til
  • TileActions.clear() sets a tile to frame 0 and removes all modifiers
  • TileActions.removeModifier() removes the current modifiers on the tile
  • TileActions.setModifier(TileModifier... tileModifiers) puts tile modifiers on tiles
  • TileActions.copyFrom(Tile tile) copies frame/modifiers etc from another tile

you can move the whole map using .shift(int x, int y, TileAction defaultAction)

where x,y is the amount and direction to move the map in, and defaultAction is what to do where new empty tiles appear (due to shifting)

to iterate the whole map or sections of it, you'd normally create a nested x,y loop however an easier option is to use the iterate(MapIterator mapIterator) and iterate(int x1, int y1, int x2, int y2, MapIterator mapIterator) and implementing the MapIterator interface, for example:

map.iterate(new MapIterator() // basic example filling the whole map with frame 5
{
	@Override
	public void process(int x, int y, Tile tile)
	{
		tile.setFrame(5);
	}
});

you can copy/paste any sections of the map using the copy(int x1, int y1, int x2, int y2) to get a MapSection which can then be pasted back using pasteInto(MapArray target, int x, int y) or centeredPasteInto(MapArray target, int x, int y)

Clone this wiki locally