API Docs for: 0.1.1
Show:

flatworld.maplayers.MapLayer Class

Creates a basic layer for the Map. This type of layer can not hold subcontainers. Note that different devices and graphic cards can only have specific size of bitmap drawn, and PIXI cache always draws a bitmap thus the default is: 4096, based on this site: http://webglstats.com/ and MAX_TEXTURE_SIZE. This is important also when caching.

Constructor

flatworld.maplayers.MapLayer

(
  • options
)

Parameters:

  • options Object

    optional options

    • name String

      Layers name, used for identifying the layer. Useful in debugging, but can be used for finding correct layers too

    • coord Object

      coord starting coords of layer. Relative to parent map layer.

      • x Integer
        X coordinate
      • y Integer
        Y coordinate
    • specialLayer Object

      Is this layer special (e.g. UILayer not included in normal operations)

      • x Integer
        X coordinate
      • y Integer
        Y coordinate

Methods

addUIObject

(
  • object
  • UIName
)
Array

Adds and object to this layers UILayer child. If an object with the same name already exists, we remove it automatically and replace it with the new object given as parameter.

Parameters:

  • object Object

    The UI object to be added under this layer

  • UIName Object

    Name of the UI object. This is important as you can use it to remove the UI object later or replace it.

Returns:

Array:

All the UIObjects currently on this layer

createUILayer

(
  • name
  • coord
)
MapLayer

Create and add special layer, that holds UI effects in it. UILayer is normally positioned as movableLayers 3rd child. And the actual UI stuff is added there.

Parameters:

  • name String

    name of the layer

  • coord Object

    Coordinates of the layer

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

Returns:

MapLayer:

The created UI layer

deleteUIObjects

(
  • object
)
Array

If object is given, removes that object, otherwiseRemove all the UIObjects from this layer

Parameters:

  • object Object

    If you wish to delete particular object

Returns:

Array:

empty UIObjects array

getObjects

() Array

Get all objects that are this layers children or subcontainers children. Does not return layers, but the objects. Works on primary layer only currently. So can not seek for complicated children structure, seeks only inside subcontainers.

Returns:

Array:

All the objects (not layers) found under this layer

getPrimaryLayers

() Array

Get primary layers, that this layer holds as children. So basically all children that are not special layers (such as UI layers etc.)

Returns:

Array:

Primary children layers under this layer

getUILayer

() MapLayer | undefined

Return the UILayer. If no UILayer is yet created, will return undefined

Returns:

MapLayer | undefined:

getUIObjects

() Array

get UIObjects on this layer, if there are any, or defaulty empty array if no UIObjects are active

Returns:

Array:

current UIObjects

getZoom

() Boolean

get layer zoom

Returns:

Boolean:

current amount of zoom

hasSubcontainers

() Boolean

Does this layer use subcontainers.

Returns:

Boolean:

true = uses subcontainers.

move

(
  • coord
)

Move layer based on given amounts

Parameters:

  • coord Object

    The amount of x and y coordinates we want the layer to move. I.e. { x: 5, y: 0 }. This would move the map 5 pixels horizontally and 0 pixels vertically

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

setZoom

(
  • amount
)
Number

set layer zoom

Parameters:

  • amount Number

    The amount that you want the layer to zoom.

Returns:

Number:

The same amount that was given, except after transform to 2 decimals and type cast to Number

Attributes

name

String

Layers name, used for identifying the layer. Useful in debugging, but can be used for finding correct layers too

Fires event nameChange

Fires when the value for the configuration attribute name is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

selectable

Boolean

Can you select objects from this layer. For example with Map.getObjectsUnderArea

Fires event selectableChange

Fires when the value for the configuration attribute selectable is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

specialLayer

Boolean

Is this layer special (e.g. UILayer not included in normal operations)

Fires event specialLayerChange

Fires when the value for the configuration attribute specialLayer is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

static

Boolean

Will this layer change dynamically or can we assume that this holds the same objects always, until game reload

Fires event staticChange

Fires when the value for the configuration attribute static is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

UIObjectList

Array

Every added UIObject will be listed here for removal and updating. The indexes in the list provide the easy option to remove only certain object from the UIObjects.

Fires event UIObjectListChange

Fires when the value for the configuration attribute UIObjectList is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.