mirror of
https://github.com/wassname/phaser.git
synced 2026-06-30 16:40:20 +08:00
Fixed Animation index 0 issue and hooked TilemapLayer to camera.
This commit is contained in:
@@ -101,7 +101,7 @@ Phaser.AnimationManager.prototype = {
|
||||
// If they didn't set the useNumericIndex then let's at least try and guess it
|
||||
if (typeof useNumericIndex === 'undefined')
|
||||
{
|
||||
if (frames && frames[0] && typeof frames[0] === 'number')
|
||||
if (frames && typeof frames[0] === 'number')
|
||||
{
|
||||
useNumericIndex = true;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ Phaser.FrameData.prototype = {
|
||||
*/
|
||||
getFrame: function (index) {
|
||||
|
||||
if (this._frames[index])
|
||||
if (this._frames.length > index)
|
||||
{
|
||||
return this._frames[index];
|
||||
}
|
||||
|
||||
@@ -661,6 +661,6 @@ Phaser.Rectangle.union = function (a, b, out) {
|
||||
|
||||
if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
|
||||
|
||||
return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom));
|
||||
return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right) - Math.min(a.left, b.left), Math.max(a.bottom, b.bottom) - Math.min(a.top, b.top));
|
||||
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
this.preX = sprite.x;
|
||||
this.preY = sprite.y;
|
||||
this.preRotation = sprite.angle;
|
||||
this.screenX = sprite.x;
|
||||
this.screenY = sprite.y;
|
||||
|
||||
// un-scaled original size
|
||||
this.sourceWidth = sprite.currentFrame.sourceSizeW;
|
||||
@@ -108,8 +110,10 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
this.embedded = false;
|
||||
|
||||
this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.screenX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.screenY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preRotation = this.sprite.angle;
|
||||
|
||||
this.x = this.preX;
|
||||
@@ -233,8 +237,10 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
|
||||
this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
// this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
// this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preRotation = this.sprite.angle;
|
||||
|
||||
this.x = this.preX;
|
||||
|
||||
@@ -323,8 +323,7 @@ Phaser.Device.prototype = {
|
||||
|
||||
this.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
|
||||
this.fileSystem = !!window['requestFileSystem'];
|
||||
this.webGL = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )();
|
||||
// this.webGL = !!window['WebGLRenderingContext'];
|
||||
this.webGL = ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )();
|
||||
this.worker = !!window['Worker'];
|
||||
|
||||
if ('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
|
||||
|
||||
+30
-10
@@ -37,6 +37,7 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset,
|
||||
* @default
|
||||
*/
|
||||
this.sprite = new Phaser.Sprite(this.game, x, y, this.texture, this.frame);
|
||||
this.sprite.fixedToCamera = true;
|
||||
|
||||
|
||||
/**
|
||||
@@ -167,6 +168,21 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset,
|
||||
|
||||
Phaser.TilemapLayer.prototype = {
|
||||
|
||||
update: function () {
|
||||
|
||||
this.x = this.game.camera.x;
|
||||
this.y = this.game.camera.y;
|
||||
|
||||
},
|
||||
|
||||
resizeWorld: function () {
|
||||
|
||||
this.game.world.setBounds(0, 0, this.widthInPixels, this.heightInPixels);
|
||||
|
||||
console.log('world', this.game.world.bounds);
|
||||
|
||||
},
|
||||
|
||||
updateTileset: function (tileset) {
|
||||
|
||||
if (tileset instanceof Phaser.Tileset)
|
||||
@@ -242,11 +258,14 @@ Phaser.TilemapLayer.prototype = {
|
||||
height = this.heightInPixels;
|
||||
}
|
||||
|
||||
var tileWidth = this.tileWidth * this.sprite.scale.x;
|
||||
var tileHeight = this.tileHeight * this.sprite.scale.y;
|
||||
|
||||
// Convert the pixel values into tile coordinates
|
||||
this._tx = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
|
||||
this._ty = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
|
||||
this._tw = (this.game.math.snapToCeil(width, this.tileWidth) + this.tileWidth) / this.tileWidth;
|
||||
this._th = (this.game.math.snapToCeil(height, this.tileHeight) + this.tileHeight) / this.tileHeight;
|
||||
this._tx = this.game.math.snapToFloor(x, tileWidth) / tileWidth;
|
||||
this._ty = this.game.math.snapToFloor(y, tileHeight) / tileHeight;
|
||||
this._tw = (this.game.math.snapToCeil(width, tileWidth) + tileWidth) / tileWidth;
|
||||
this._th = (this.game.math.snapToCeil(height, tileHeight) + tileHeight) / tileHeight;
|
||||
|
||||
this._results.length = 0;
|
||||
|
||||
@@ -254,6 +273,8 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
var _index = 0;
|
||||
var _tile = null;
|
||||
var sx = 0;
|
||||
var sy = 0;
|
||||
|
||||
for (var wy = this._ty; wy < this._ty + this._th; wy++)
|
||||
{
|
||||
@@ -265,9 +286,13 @@ Phaser.TilemapLayer.prototype = {
|
||||
_index = this.layer.data[wy][wx] - 1;
|
||||
_tile = this.tileset.getTile(_index);
|
||||
|
||||
sx = _tile.width * this.sprite.scale.x;
|
||||
sy = _tile.height * this.sprite.scale.y;
|
||||
|
||||
if (collides == false || (collides && _tile.collideNone == false))
|
||||
{
|
||||
this._results.push({ x: wx * _tile.width, right: (wx * _tile.width) + _tile.width, y: wy * _tile.height, bottom: (wy * _tile.height) + _tile.height, width: _tile.width, height: _tile.height, tx: wx, ty: wy, tile: _tile });
|
||||
// this._results.push({ x: wx * _tile.width, right: (wx * _tile.width) + _tile.width, y: wy * _tile.height, bottom: (wy * _tile.height) + _tile.height, width: _tile.width, height: _tile.height, tx: wx, ty: wy, tile: _tile });
|
||||
this._results.push({ x: wx * sx, right: (wx * sx) + sx, y: wy * sy, bottom: (wy * sy) + sy, width: sx, height: sy, tx: wx, ty: wy, tile: _tile });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,11 +343,6 @@ Phaser.TilemapLayer.prototype = {
|
||||
this._tx = this._dx;
|
||||
this._ty = this._dy;
|
||||
|
||||
// First let's just copy over the whole canvas, offset by the scroll difference
|
||||
|
||||
// Then we only need fill in the missing strip/s (could be top/bottom/left/right I guess)
|
||||
// ScrollZone code might be useful here.
|
||||
|
||||
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
|
||||
for (var y = this._startY; y < this._startY + this._maxY; y++)
|
||||
|
||||
+1
-2
@@ -626,8 +626,7 @@ Phaser.Utils.Debug.prototype = {
|
||||
this.start(0, 0, color);
|
||||
|
||||
this.context.fillStyle = color;
|
||||
// this.context.fillRect(sprite.body.x - sprite.body.deltaX(), sprite.body.y - sprite.body.deltaY(), sprite.body.width, sprite.body.height);
|
||||
this.context.fillRect(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height);
|
||||
this.context.fillRect(sprite.body.screenX, sprite.body.screenY, sprite.body.width, sprite.body.height);
|
||||
|
||||
this.stop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user