mirror of
https://github.com/wassname/phaser.git
synced 2026-07-23 13:00:41 +08:00
Tilemap collision is now working but all Camera following seems to be broken as a result. Awesome.
This commit is contained in:
@@ -174,7 +174,7 @@ module Phaser {
|
||||
*
|
||||
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
||||
*/
|
||||
public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0.8): Emitter {
|
||||
public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0): Emitter {
|
||||
|
||||
this.maxSize = Quantity;
|
||||
|
||||
@@ -236,8 +236,10 @@ module Phaser {
|
||||
|
||||
if (Collide > 0)
|
||||
{
|
||||
particle.width *= Collide;
|
||||
particle.height *= Collide;
|
||||
particle.allowCollisions = Collision.ANY;
|
||||
particle.elasticity = Collide;
|
||||
//particle.width *= Collide;
|
||||
//particle.height *= Collide;
|
||||
//particle.centerOffsets();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -29,8 +29,8 @@ module Phaser {
|
||||
this.last = new MicroPoint(x, y);
|
||||
this.origin = new MicroPoint(this.bounds.halfWidth, this.bounds.halfHeight);
|
||||
this.align = GameObject.ALIGN_TOP_LEFT;
|
||||
this.mass = 1.0;
|
||||
this.elasticity = 0.0;
|
||||
this.mass = 1;
|
||||
this.elasticity = 0;
|
||||
this.health = 1;
|
||||
this.immovable = false;
|
||||
this.moves = true;
|
||||
@@ -52,7 +52,7 @@ module Phaser {
|
||||
this.maxAngular = 10000;
|
||||
|
||||
this.cameraBlacklist = [];
|
||||
this.scrollFactor = new MicroPoint(1.0, 1.0);
|
||||
this.scrollFactor = new MicroPoint(1, 1);
|
||||
|
||||
}
|
||||
|
||||
@@ -245,17 +245,6 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
if (typeof ObjectOrGroup === 'Tilemap')
|
||||
{
|
||||
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
|
||||
// we redirect the call to the tilemap overlap here.
|
||||
return ObjectOrGroup.overlaps(this, InScreenSpace, Camera);
|
||||
}
|
||||
*/
|
||||
|
||||
//var object: GameObject = ObjectOrGroup;
|
||||
|
||||
if (!InScreenSpace)
|
||||
{
|
||||
return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) &&
|
||||
@@ -308,20 +297,6 @@ module Phaser {
|
||||
return results;
|
||||
}
|
||||
|
||||
/*
|
||||
if (typeof ObjectOrGroup === 'Tilemap')
|
||||
{
|
||||
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
|
||||
// we redirect the call to the tilemap overlap here.
|
||||
//However, since this is overlapsAt(), we also have to invent the appropriate position for the tilemap.
|
||||
//So we calculate the offset between the player and the requested position, and subtract that from the tilemap.
|
||||
var tilemap: Tilemap = ObjectOrGroup;
|
||||
return tilemap.overlapsAt(tilemap.x - (X - this.x), tilemap.y - (Y - this.y), this, InScreenSpace, Camera);
|
||||
}
|
||||
*/
|
||||
|
||||
//var object: GameObject = ObjectOrGroup;
|
||||
|
||||
if (!InScreenSpace)
|
||||
{
|
||||
return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) &&
|
||||
|
||||
@@ -43,6 +43,7 @@ module Phaser {
|
||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
||||
*/
|
||||
public update() {
|
||||
|
||||
//lifespan behavior
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ module Phaser {
|
||||
public tiles : Tile[];
|
||||
public layers : TilemapLayer[];
|
||||
public currentLayer: TilemapLayer;
|
||||
public collisionLayer: TilemapLayer;
|
||||
public mapFormat: number;
|
||||
|
||||
public update() {
|
||||
@@ -90,11 +91,14 @@ module Phaser {
|
||||
var tileQuantity = layer.parseTileOffsets();
|
||||
|
||||
this.currentLayer = layer;
|
||||
this.collisionLayer = layer;
|
||||
|
||||
this.layers.push(layer);
|
||||
|
||||
this.generateTiles(tileQuantity);
|
||||
|
||||
console.log('generate layer csv');
|
||||
|
||||
}
|
||||
|
||||
private parseTiledJSON(data: string, key: string) {
|
||||
@@ -132,6 +136,7 @@ module Phaser {
|
||||
layer.addColumn(row);
|
||||
c = 0;
|
||||
}
|
||||
console.log('generate layer json');
|
||||
}
|
||||
|
||||
layer.updateBounds();
|
||||
@@ -139,6 +144,7 @@ module Phaser {
|
||||
var tileQuantity = layer.parseTileOffsets();
|
||||
|
||||
this.currentLayer = layer;
|
||||
this.collisionLayer = layer;
|
||||
|
||||
this.layers.push(layer);
|
||||
|
||||
@@ -167,20 +173,20 @@ module Phaser {
|
||||
|
||||
// Tile Collision
|
||||
|
||||
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY) {
|
||||
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions: bool = false) {
|
||||
|
||||
for (var i = start; i < end; i++)
|
||||
{
|
||||
this.tiles[i].allowCollisions = collision;
|
||||
this.tiles[i].setCollision(collision, resetCollisions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY) {
|
||||
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions: bool = false) {
|
||||
|
||||
for (var i = 0; i < values.length; i++)
|
||||
{
|
||||
this.tiles[values[i]].allowCollisions = collision;
|
||||
this.tiles[values[i]].setCollision(collision, resetCollisions);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -222,21 +228,32 @@ module Phaser {
|
||||
// Group?
|
||||
if (objectOrGroup.isGroup == false)
|
||||
{
|
||||
if (objectOrGroup.exists && objectOrGroup.allowCollisions != Collision.NONE)
|
||||
{
|
||||
this.currentLayer.getTileOverlaps(objectOrGroup);
|
||||
}
|
||||
return this.collideGameObject(objectOrGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
// todo
|
||||
objectOrGroup.forEachAlive(this.currentLayer.getTileOverlaps);
|
||||
objectOrGroup.forEachAlive(this, this.collideGameObject, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public collideGameObject(object: GameObject): bool {
|
||||
|
||||
if (object == this) { return false; }
|
||||
|
||||
if (object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
|
||||
{
|
||||
return this.collisionLayer.getTileOverlaps(object);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Set current layer
|
||||
// Set layer order?
|
||||
|
||||
Reference in New Issue
Block a user