mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Updated originX/Y to use a normalized value between 0 and 1. Added the properties displayOriginX and displayOriginY (read only) to hold the calculated pixel values. Updated renderers to use these values.
This commit is contained in:
parent
d0de931c93
commit
22154d905d
7 changed files with 32 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
||||||
var CHECKSUM = {
|
var CHECKSUM = {
|
||||||
build: '37d7f8f0-091a-11e7-8491-f9d6d424c789'
|
build: '867d0fc0-09d0-11e7-a41f-615c7733ee76'
|
||||||
};
|
};
|
||||||
module.exports = CHECKSUM;
|
module.exports = CHECKSUM;
|
|
@ -3,24 +3,30 @@
|
||||||
|
|
||||||
var Origin = {
|
var Origin = {
|
||||||
|
|
||||||
originX: 0,
|
originX: 0.5,
|
||||||
originY: 0,
|
originY: 0.5,
|
||||||
|
|
||||||
|
// READ ONLY
|
||||||
|
displayOriginX: 0,
|
||||||
|
displayOriginY: 0,
|
||||||
|
|
||||||
setOrigin: function (x, y)
|
setOrigin: function (x, y)
|
||||||
{
|
{
|
||||||
if (x === undefined) { x = 0; }
|
if (x === undefined) { x = 0.5; }
|
||||||
if (y === undefined) { y = x; }
|
if (y === undefined) { y = x; }
|
||||||
|
|
||||||
this.originX = x;
|
this.originX = x;
|
||||||
this.originY = y;
|
this.originY = y;
|
||||||
|
|
||||||
|
this.displayOriginX = x * this.width;
|
||||||
|
this.displayOriginY = y * this.height;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
setOriginToCenter: function ()
|
setOriginToCenter: function ()
|
||||||
{
|
{
|
||||||
this.originX = this.frame.centerX;
|
this.setOrigin(0.5);
|
||||||
this.originY = this.frame.centerY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,14 +22,14 @@ var Texture = {
|
||||||
{
|
{
|
||||||
this.renderFlags |= _FLAG;
|
this.renderFlags |= _FLAG;
|
||||||
|
|
||||||
if (this.hasOwnProperty('originX'))
|
// if (this.hasOwnProperty('originX'))
|
||||||
{
|
// {
|
||||||
// Default origin to the center
|
// // Default origin to the center
|
||||||
var w = Math.floor(this.frame.realWidth / 2);
|
// var w = Math.floor(this.frame.realWidth / 2);
|
||||||
var h = Math.floor(this.frame.realHeight / 2);
|
// var h = Math.floor(this.frame.realHeight / 2);
|
||||||
|
|
||||||
this.setOrigin(w, h);
|
// this.setOrigin(w, h);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -16,7 +16,6 @@ var Text = new Class({
|
||||||
Components.GetBounds,
|
Components.GetBounds,
|
||||||
Components.Origin,
|
Components.Origin,
|
||||||
Components.ScaleMode,
|
Components.ScaleMode,
|
||||||
Components.Size,
|
|
||||||
Components.Transform,
|
Components.Transform,
|
||||||
Components.Visible,
|
Components.Visible,
|
||||||
TextRender
|
TextRender
|
||||||
|
@ -46,7 +45,7 @@ var Text = new Class({
|
||||||
|
|
||||||
this.style = new TextStyle(this, style);
|
this.style = new TextStyle(this, style);
|
||||||
|
|
||||||
this.autoRound = false;
|
this.autoRound = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Regular Expression that is used to split the text up into lines, in
|
* The Regular Expression that is used to split the text up into lines, in
|
||||||
|
@ -62,6 +61,9 @@ var Text = new Class({
|
||||||
|
|
||||||
this.padding = { x: 0, y: 0 };
|
this.padding = { x: 0, y: 0 };
|
||||||
|
|
||||||
|
this.width = 1;
|
||||||
|
this.height = 1;
|
||||||
|
|
||||||
if (text !== '')
|
if (text !== '')
|
||||||
{
|
{
|
||||||
this.updateText();
|
this.updateText();
|
||||||
|
@ -88,6 +90,9 @@ var Text = new Class({
|
||||||
|
|
||||||
var textSize = GetTextSize(this, size, lines);
|
var textSize = GetTextSize(this, size, lines);
|
||||||
|
|
||||||
|
this.width = textSize.width;
|
||||||
|
this.height = textSize.height;
|
||||||
|
|
||||||
canvas.width = textSize.width * this.resolution;
|
canvas.width = textSize.width * this.resolution;
|
||||||
canvas.height = textSize.height * this.resolution;
|
canvas.height = textSize.height * this.resolution;
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
|
||||||
renderer.currentScaleMode = src.scaleMode;
|
renderer.currentScaleMode = src.scaleMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dx = src.x - src.originX - camera.scrollX;
|
var dx = src.x - src.displayOriginX - camera.scrollX;
|
||||||
var dy = src.y - src.originY - camera.scrollY;
|
var dy = src.y - src.displayOriginY - camera.scrollY;
|
||||||
|
|
||||||
var canvas = src.canvas;
|
var canvas = src.canvas;
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ var DrawImage = function (src, camera)
|
||||||
// ctx[this.smoothProperty] = (source.scaleMode === ScaleModes.LINEAR);
|
// ctx[this.smoothProperty] = (source.scaleMode === ScaleModes.LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
var dx = frame.x - src.originX;
|
var dx = frame.x - src.displayOriginX;
|
||||||
var dy = frame.y - src.originY;
|
var dy = frame.y - src.displayOriginY;
|
||||||
|
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.translate(src.x - camera.scrollX, src.y - camera.scrollY);
|
ctx.translate(src.x - camera.scrollX, src.y - camera.scrollY);
|
||||||
|
|
|
@ -197,8 +197,8 @@ SpriteBatch.prototype = {
|
||||||
var scaleY = src.scaleY;
|
var scaleY = src.scaleY;
|
||||||
var rotation = -src.rotation;
|
var rotation = -src.rotation;
|
||||||
var tempMatrixMatrix = tempMatrix.matrix;
|
var tempMatrixMatrix = tempMatrix.matrix;
|
||||||
var x = -src.originX + frame.x;
|
var x = -src.displayOriginX + frame.x;
|
||||||
var y = -src.originY + frame.y;
|
var y = -src.displayOriginY + frame.y;
|
||||||
var xw = x + width;
|
var xw = x + width;
|
||||||
var yh = y + height;
|
var yh = y + height;
|
||||||
var cameraMatrix = camera.matrix.matrix;
|
var cameraMatrix = camera.matrix.matrix;
|
||||||
|
|
Loading…
Reference in a new issue