Tilemap#createFromObjects()

createFromObjects(name, gid, key, frame, exists, autoCull, group, CustomClass, adjustY)

Creates a Sprite for every object matching the given gid in the map data. You can optionally specify the group that the Sprite will be created in. If none is
given it will be created in the World. All properties from the map data objectgroup are copied across to the Sprite, so you can use this as an easy way to
configure Sprite properties from within the map editor. For example giving an object a property of alpha: 0.5 in the map editor will duplicate that when the
Sprite is created. You could also give it a value like: body.velocity.x: 100 to set it moving automatically.

Parameters
Name Type Argument Default Description
name string

The name of the Object Group to create Sprites from.

gid number

The layer array index value, or if a string is given the layer name within the map data.

key string

The Game.cache key of the image that this Sprite will use.

frame number | string <optional>

If the Sprite image contains multiple frames you can specify which one to use here.

exists boolean <optional>
true

The default exists state of the Sprite.

autoCull boolean <optional>
false

The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range.

group Phaser.Group <optional>
Phaser.World

Group to add the Sprite to. If not specified it will be added to the World group.

CustomClass object <optional>
Phaser.Sprite

If you wish to create your own class, rather than Phaser.Sprite, pass the class here. Your class must extend Phaser.Sprite and have the same constructor parameters.

adjustY boolean <optional>
true

By default the Tiled map editor uses a bottom-left coordinate system. Phaser uses top-left. So most objects will appear too low down. This parameter moves them up by their height.

Source code: tilemap/Tilemap.js (Line 378)
doc_phaser
2017-02-14 11:15:11
Comments
Leave a Comment

Please login to continue.