API Docs for: 0.1.0
Show:

CG.Map Class

Extends CG.Entity TODO spacing and margin ? TODO own buffer for drawing => split screen possible? TODO update & draw method 50%
Module: CG

CG.Map supports loading and rendering maps from the editor Tiled. XML and JSON file types are supported. XML => supported tiled encodings are csv and xml (see settings!). base64, base64(gzip) and base64(zlib) are not supported!

Supported types of the object layer are:

  • object/group (rectangle?)
  • tile element, reference point is bottom/left of the tile in the editor

These object layer types are used to generate Point and Bound objects and can be used to position sprites, what ever in the map.

Methods

addElement

(
  • element
)

Adds a object to the element array, used at the moment for collision detection to tilemap.

Parameters:

  • element Obj

    to to add to elements array

checkElementsToAreasCollision

(
  • objarray
  • callback
)

Checks if a external object(s) collides with the areas of the tiled map. This can be elements from an layer or the map itself.

Parameters:

  • objarray Array

    to check for a areas collision

  • callback Callback

    what should happen

checkMapCollision

(
  • element
  • rx
  • ry
)
Boolean

Checks if the attached element collides with an tile of the tilemap

Parameters:

  • element Obj

    to check for

  • rx Number

    current rx of rendermap method

  • ry Number

    current ry of rendermap method

Returns:

Boolean:

returns true or false

drawMap

(
  • sx
  • sy
  • bx
  • by
  • bw
  • bh
  • callback
)

This is the main method for map drawing. Orthogonal maps works very well. Isometric maps are not well implemented yet.

Parameters:

  • sx Number

    sx top left coord for canvas drawing

  • sy Number

    sy top left coord for canvas drawing

  • bx Number

    bx top left x coord of bound in tilemap

  • by Number

    by top left y coord of bound in tilemap

  • bw Number

    bw width of bound in tilemap

  • bh Number

    bh height of bound in tilemap

  • callback Callback

    callback for collision handling - callback(obj,maptileproperties)

getAreasByName

(
  • name
)
False/array

Get all areas with the given name

Parameters:

  • name String

    name of the area(s) to return

Returns:

False/array:

returns false or an array with area(s)

getBounds

()

Get the bounds of the map

getPointsByName

(
  • name
)
False/array

Get all point(s) with the given name in the points

Parameters:

  • name String

    name of the points to return

Returns:

False/array:

returns false or an array with point(s)

init

()

Returns:

:

loadMapJson

(
  • jsonfile
)

Load and parse an tilemap json file. Use the tiled json export. Hopefully the json format has the same functionality as the xml loader ;o)

Parameters:

  • jsonfile String/object

    jsonfile path or mediaasset object with data of tiled map xml

loadMapXml

(
  • xmlfile
)

Load and parse an xml tilemap file. It can handle the tiled XML and CSV format. All other formats are not supported!

Parameters:

  • xmlfile String/object

    xmlfile path or mediaasset object with data of tiled map xml

removeJsonData

()

removes the json data of the map object

removeXmlData

()

removes the xml data of the map object

setLayerToRender

(
  • mixed
)

Defines layer drawing, See property options

Parameters:

  • mixed Mixed

    mixed define the map layer(s) to render 'all' (string) for all layers, array index (integer) for layer to render or 'name' (string) of layer to render'

update

()

The update method is not complete yet and only experimental. At the final stage the methods updateAnimation and updatePointsAndAreas have to be called from here! Then also a map class can be added to a layer as an element for auto update/draw from Game.director!

updateAnimation

()

Updates all tilemap properties of the map.

Supported custom tiled map properties for now are (see also tilemap examples): anim_delay => time to used to display an switch to next tile anim_direction => direction for next tile 1 = jump forward, -1 = jump back anim_next => defines the offset

With this tile properties it is possible to define tilemap animations. These must be defined in the tilemap property window with key/value pairs

updatePointsAndAreas

()

Update all areas and points elements.

Properties

animDelayFactor

Number

areas

Array

atlas

Image

atlasheight

Number

atlastranscol

String

atlaswidth

Number

elements

Array

layers

Array

The tiled layer are parsed into separate layers

layertocheck

Number

mapColumns

Number

mapOffset

CG.Point

mapRows

Number

orientation

String

parser

DOMParser

points

Array

position

CG.Point

renderlayer

String

Defines the layer to draw: all - for all layers name - the name of layer to draw index - array index of layer

tileheight

Number

tileproperties

Array

tileset

Object

tilewidth

Number

wrapX

Boolean deprecated

wrapY

Boolean deprecated

xmlDoc

String