CG.Map Class
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.
Item Index
Methods
Properties
- alpha
- animDelayFactor
- areas
- atlas
- atlasheight
- atlastranscol
- atlaswidth
- elements
- height
- json
- layers
- layertocheck
- mapColumns
- mapOffset
- mapRows
- orientation
- parser
- points
- position
- renderlayer
- tileheight
- tileproperties
- tileset
- tilewidth
- width
- wrapX deprecated
- wrapY deprecated
- xml
- xmlDoc
- xscale
- xspeed
- yscale
- yspeed
Methods
addElement
-
element
Adds a object to the element array, used at the moment for collision detection to tilemap.
Parameters:
-
element
Objto 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
Arrayto check for a areas collision
-
callback
Callbackwhat should happen
checkMapCollision
-
element
-
rx
-
ry
Checks if the attached element collides with an tile of the tilemap
Parameters:
Returns:
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
Numbersx top left coord for canvas drawing
-
sy
Numbersy top left coord for canvas drawing
-
bx
Numberbx top left x coord of bound in tilemap
-
by
Numberby top left y coord of bound in tilemap
-
bw
Numberbw width of bound in tilemap
-
bh
Numberbh height of bound in tilemap
-
callback
Callbackcallback for collision handling - callback(obj,maptileproperties)
getAreasByName
-
name
Get all areas with the given name
Parameters:
-
name
Stringname of the area(s) to return
Returns:
returns false or an array with area(s)
getBounds
()
Get the bounds of the map
getPointsByName
-
name
Get all point(s) with the given name in the points
Parameters:
-
name
Stringname of the points to return
Returns:
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/objectjsonfile 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/objectxmlfile 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
Mixedmixed 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
atlas
Image
parser
DOMParser
renderlayer
String
Defines the layer to draw: all - for all layers name - the name of layer to draw index - array index of layer