mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Tilemap.createFromObjects can now turn a bunch of Tiled objects into Sprites in one single call, and copies across all properties as well.
This commit is contained in:
parent
63d90a0176
commit
bf72b4d3b0
7 changed files with 102 additions and 15 deletions
|
@ -48,6 +48,7 @@ Significant API changes:
|
|||
|
||||
* Loader.tileset has a new method signature. Please use the new format: load.tileset(key, url, tileWidth, tileHeight, tileMargin, tileSpacing, rows, columns, total).
|
||||
* TilemapLayers are now created via the Tilemap object itself: map.createLayer(x, y, width, height, tileset, layer, group) and no longer via the GameObjectFactory.
|
||||
* Tilemap.createFromObjects can now turn a bunch of Tiled objects into Sprites in one single call, and copies across all properties as well.
|
||||
|
||||
|
||||
New features:
|
||||
|
@ -60,6 +61,7 @@ New features:
|
|||
* TilemapLayers now have debug and debugAlpha values, this turns on the drawing of the collision edges (very handy for debugging, as the name implies!)
|
||||
* Tweens have a new event: onLoop.
|
||||
* You can now load any binary file via the Loader: game.load.binary(key, url, callback) - the optional callback allows for post-load processing before entering the Cache.
|
||||
* Group.set will let you deep set a new propery on a single child of the Group.
|
||||
|
||||
|
||||
New Examples:
|
||||
|
|
|
@ -84,13 +84,13 @@
|
|||
"name":"",
|
||||
"properties":
|
||||
{
|
||||
|
||||
"alpha":"0.5"
|
||||
},
|
||||
"type":"",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":454,
|
||||
"y":307
|
||||
"x":443,
|
||||
"y":244
|
||||
},
|
||||
{
|
||||
"gid":34,
|
||||
|
@ -112,7 +112,7 @@
|
|||
"name":"",
|
||||
"properties":
|
||||
{
|
||||
|
||||
"alpha":"0.5"
|
||||
},
|
||||
"type":"",
|
||||
"visible":true,
|
||||
|
@ -140,7 +140,7 @@
|
|||
"name":"",
|
||||
"properties":
|
||||
{
|
||||
|
||||
"body.gravity.y":"5"
|
||||
},
|
||||
"type":"",
|
||||
"visible":true,
|
||||
|
|
|
@ -49,11 +49,23 @@
|
|||
<object name="sun" type="collision" x="793" y="340" width="77" height="70">
|
||||
<ellipse/>
|
||||
</object>
|
||||
<object gid="34" x="454" y="307"/>
|
||||
<object gid="34" x="443" y="244">
|
||||
<properties>
|
||||
<property name="alpha" value="0.5"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object gid="34" x="483" y="267"/>
|
||||
<object gid="34" x="513" y="237"/>
|
||||
<object gid="34" x="513" y="237">
|
||||
<properties>
|
||||
<property name="alpha" value="0.5"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object gid="34" x="549" y="229"/>
|
||||
<object gid="34" x="580" y="249"/>
|
||||
<object gid="34" x="580" y="249">
|
||||
<properties>
|
||||
<property name="body.gravity.y" value="5"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object gid="34" x="610" y="278"/>
|
||||
<object gid="34" x="639" y="309"/>
|
||||
<object gid="34" x="662" y="342"/>
|
||||
|
|
|
@ -20,12 +20,14 @@ function preload() {
|
|||
// game.load.image('phaser', 'assets/sprites/mushroom2.png');
|
||||
// game.load.image('phaser', 'assets/sprites/wabbit.png');
|
||||
game.load.image('phaser', 'assets/sprites/arrow.png');
|
||||
game.load.spritesheet('coin', 'assets/sprites/coin.png', 32, 32);
|
||||
// game.load.image('phaser', 'assets/sprites/darkwing_crazy.png');
|
||||
|
||||
}
|
||||
|
||||
var cursors;
|
||||
var map;
|
||||
var coins;
|
||||
|
||||
var layer;
|
||||
var layer2;
|
||||
|
@ -57,13 +59,13 @@ function create() {
|
|||
// layer2.alpha = 0.5;
|
||||
|
||||
layer = map.createLayer('Tile Layer 1');
|
||||
layer.scrollFactorX = 0.5;
|
||||
|
||||
// layer.debug = true;
|
||||
|
||||
layer.resizeWorld();
|
||||
|
||||
|
||||
//coins =
|
||||
map.createFromObjects(34, 'coin', 0)
|
||||
|
||||
// layer2 = game.add.tilemapLayer(0, 0, 400, 600, null, map, 0);
|
||||
// layer.cameraOffset.x = 400;
|
||||
|
|
|
@ -335,6 +335,11 @@ Phaser.Group.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal test.
|
||||
*
|
||||
* @method Phaser.Group#childTest
|
||||
*/
|
||||
childTest: function (prefix, child) {
|
||||
|
||||
var s = prefix + ' next: ';
|
||||
|
@ -363,6 +368,11 @@ Phaser.Group.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal test.
|
||||
*
|
||||
* @method Phaser.Group#swapIndex
|
||||
*/
|
||||
swapIndex: function (index1, index2) {
|
||||
|
||||
var child1 = this.getAt(index1);
|
||||
|
@ -634,6 +644,32 @@ Phaser.Group.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* This function allows you to quickly set a property on a single child of this Group to a new value.
|
||||
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
|
||||
*
|
||||
* @method Phaser.Group#set
|
||||
* @param {Phaser.Sprite} child - The child to set the property on.
|
||||
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
|
||||
* @param {*} value - The value that will be set.
|
||||
* @param {boolean} [checkAlive=false] - If set then the child will only be updated if alive=true.
|
||||
* @param {boolean} [checkVisible=false] - If set then the child will only be updated if visible=true.
|
||||
* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
|
||||
*/
|
||||
set: function (child, key, value, checkAlive, checkVisible, operation) {
|
||||
|
||||
key = key.split('.');
|
||||
|
||||
if (typeof checkAlive === 'undefined') { checkAlive = false; }
|
||||
if (typeof checkVisible === 'undefined') { checkVisible = false; }
|
||||
|
||||
if ((checkAlive === false || (checkAlive && child.alive)) && (checkVisible === false || (checkVisible && child.visible)))
|
||||
{
|
||||
this.setProperty(child, key, value, operation);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This function allows you to quickly set the same property across all children of this Group to a new value.
|
||||
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
|
||||
|
|
|
@ -184,16 +184,51 @@ Phaser.Tilemap.prototype = {
|
|||
},
|
||||
|
||||
// Region? Remove tile from map data?
|
||||
createSpritesFromTiles: function (layer, tileIndex, key, frame, group) {
|
||||
createFromTiles: function (layer, tileIndex, key, frame, group) {
|
||||
|
||||
if (typeof group === 'undefined') { group = this.game.world; }
|
||||
|
||||
},
|
||||
|
||||
createGroup: function (layer, parent) {
|
||||
/**
|
||||
* 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 if 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.
|
||||
*
|
||||
* @method Phaser.Tileset#createFromObjects
|
||||
* @param {number} gid - The layer array index value, or if a string is given the layer name, within the map data that this TilemapLayer represents.
|
||||
* @param {string} key - The Game.cache key of the image that this Sprite will use.
|
||||
* @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here.
|
||||
* @param {boolean} [exists=true] - The default exists state of the Sprite.
|
||||
* @param {boolean} [autoCull=true] - The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range.
|
||||
* @param {Phaser.Group} [group] - Optional Group to add the Sprite to. If not specified it will be added to the World group.
|
||||
*/
|
||||
createFromObjects: function (gid, key, frame, exists, autoCull, group) {
|
||||
|
||||
// Creates a Group based on an objectgroup, with one Sprite per gid entry, using the tilemap image + frame number
|
||||
// Will only work if image is loaded as spritesheet
|
||||
if (typeof exists === 'undefined') { exists = true; }
|
||||
if (typeof autoCull === 'undefined') { autoCull = true; }
|
||||
if (typeof group === 'undefined') { group = this.game.world; }
|
||||
|
||||
var sprite;
|
||||
|
||||
for (var i = 0; i < this.objects.length; i++)
|
||||
{
|
||||
if (this.objects[i].gid === gid)
|
||||
{
|
||||
sprite = group.create(this.objects[i].x, this.objects[i].y, key, frame, exists);
|
||||
|
||||
sprite.anchor.setTo(0, 1);
|
||||
sprite.name = this.objects[i].name;
|
||||
sprite.visible = this.objects[i].visible;
|
||||
sprite.autoCull = autoCull;
|
||||
|
||||
for (property in this.objects[i].properties)
|
||||
{
|
||||
group.set(sprite, property, this.objects[i].properties[property], false, false, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -304,7 +304,7 @@ Phaser.TilemapLayer.prototype.postUpdate = function () {
|
|||
*/
|
||||
Phaser.TilemapLayer.prototype.resizeWorld = function () {
|
||||
|
||||
this.game.world.setBounds(0, 0, this.layer.widthInPixels * 4, this.layer.heightInPixels);
|
||||
this.game.world.setBounds(0, 0, this.layer.widthInPixels, this.layer.heightInPixels);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue