Phaser.CANVAS_PX_ROUND is a boolean. If 'true' the Canvas renderer will Math.floor() all coordinates before drawImage, stopping pixel interpolation. Defaults to false.

Phaser.CANVAS_CLEAR_RECT is a boolean. If 'true' (the default) it will context.clearRect() every frame. If false this is skipped (useful if you know you don't need it)
Collision now works between Sprites positioned via sprite.x/y, sprite.body.x/y or sprite.body.velocity.
If you are tweening a sprite and still want physics collision, set `sprite.body.moves = false` otherwise it will fight against the tween motion.
This commit is contained in:
photonstorm
2014-01-31 04:14:02 +00:00
parent 68b7d22e0d
commit 13a86765cb
6 changed files with 101 additions and 41 deletions
+4 -1
View File
@@ -39,7 +39,10 @@ var Phaser = Phaser || {
LEFT: 1,
RIGHT: 2,
UP: 3,
DOWN: 4
DOWN: 4,
CANVAS_PX_ROUND: false,
CANVAS_CLEAR_RECT: true
};
+27 -20
View File
@@ -4,6 +4,7 @@
* 1) Added support for Trimmed sprite sheets
* 2) Skip display objects with an alpha of zero
* 3) Avoid Style Recalculation from the incorrect bgcolor value
* 4) Added support for Canvas unit rounding via Phaser.CANVAS_PX_ROUND boolean (disabled by default).
*
* Hopefully we can remove this once Pixi has been updated to support these things.
*/
@@ -23,7 +24,12 @@ PIXI.CanvasRenderer.prototype.render = function(stage)
stage.updateTransform();
this.context.setTransform(1, 0, 0, 1, 0, 0);
this.context.clearRect(0, 0, this.width, this.height)
if (Phaser.CANVAS_CLEAR_RECT)
{
this.context.clearRect(0, 0, this.width, this.height)
}
this.renderDisplayObject(stage, false);
// Remove frame updates
@@ -44,8 +50,6 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, rend
do
{
//transform = displayObject.worldTransform;
if (!displayObject.visible && !renderHidden)
{
displayObject = displayObject.last._iNext;
@@ -60,27 +64,30 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, rend
if (displayObject instanceof PIXI.Sprite)
{
// var frame = displayObject.texture.frame;
if (displayObject.texture.frame)
{
this.context.globalAlpha = displayObject.worldAlpha;
// this.context.setTransform(
// displayObject.worldTransform[0],
// displayObject.worldTransform[3],
// displayObject.worldTransform[1],
// displayObject.worldTransform[4],
// displayObject.worldTransform[2],
// displayObject.worldTransform[5]);
this.context.setTransform(
displayObject.worldTransform[0],
displayObject.worldTransform[3],
displayObject.worldTransform[1],
displayObject.worldTransform[4],
Math.floor(displayObject.worldTransform[2]),
Math.floor(displayObject.worldTransform[5]));
if (Phaser.CANVAS_PX_ROUND)
{
this.context.setTransform(
displayObject.worldTransform[0],
displayObject.worldTransform[3],
displayObject.worldTransform[1],
displayObject.worldTransform[4],
Math.floor(displayObject.worldTransform[2]),
Math.floor(displayObject.worldTransform[5]));
}
else
{
this.context.setTransform(
displayObject.worldTransform[0],
displayObject.worldTransform[3],
displayObject.worldTransform[1],
displayObject.worldTransform[4],
displayObject.worldTransform[2],
displayObject.worldTransform[5]);
}
if (displayObject.texture.trimmed)
{
+7 -7
View File
@@ -1273,19 +1273,19 @@ if (this.sprite.debug)
this.facing = Phaser.DOWN;
}
// this.updateBounds();
if (this.sprite.debug)
{
console.log('Body postUpdate x:', this.x, 'y:', this.y, 'left:', this.left, 'right:', this.right, 'WAS', this.preX, this.preY);
console.log('Body postUpdate blocked:', this.blocked, this.blockFlags);
console.log('Body postUpdate velocity:', this.velocity.x, this.velocity.y);
console.log('Body postUpdate Sprite:', this.sprite.x, this.sprite.y, 'cached', this.sprite._cache.x, this.sprite._cache.y);
}
this.sprite.x = this.x - this.offset.x;
this.sprite.y = this.y - this.offset.y;
this.sprite.worldTransform[2] = this.x - this.offset.x;
this.sprite.worldTransform[5] = this.y - this.offset.y;
if (this.deltaX() !== 0 || this.deltaY() !== 0)
{
this.sprite.worldTransform[2] = this.sprite.x = (this.x - this.offset.x);
this.sprite.worldTransform[5] = this.sprite.y = (this.y - this.offset.y);
}
if (this.allowRotation)
{
@@ -1319,7 +1319,7 @@ if (this.sprite.debug)
this.mass = 1;
this.friction = 0.1;
this.checkCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
this.blocked
this.blocked = { x: 0, y: 0, up: false, down: false, left: false, right: false };
},
+1 -3
View File
@@ -734,8 +734,6 @@ Phaser.TilemapLayer.prototype.render = function () {
this._ty = this._dy;
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
// this.context.fillStyle = '#ff00ff';
// this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.context.fillStyle = this.tileColor;
@@ -802,7 +800,7 @@ Phaser.TilemapLayer.prototype.render = function () {
if (tile.debug)
{
this.context.fillStyle = 'rgba(0,255,0,0.5)';
this.context.fillStyle = 'rgba(0, 255, 0, 0.4)';
this.context.fillRect(Math.floor(this._tx), Math.floor(this._ty), this.map.tileWidth, this.map.tileHeight);
}
}