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 = {
|
||||
build: '37d7f8f0-091a-11e7-8491-f9d6d424c789'
|
||||
build: '867d0fc0-09d0-11e7-a41f-615c7733ee76'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -3,24 +3,30 @@
|
|||
|
||||
var Origin = {
|
||||
|
||||
originX: 0,
|
||||
originY: 0,
|
||||
originX: 0.5,
|
||||
originY: 0.5,
|
||||
|
||||
// READ ONLY
|
||||
displayOriginX: 0,
|
||||
displayOriginY: 0,
|
||||
|
||||
setOrigin: function (x, y)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
if (x === undefined) { x = 0.5; }
|
||||
if (y === undefined) { y = x; }
|
||||
|
||||
this.originX = x;
|
||||
this.originY = y;
|
||||
|
||||
this.displayOriginX = x * this.width;
|
||||
this.displayOriginY = y * this.height;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
setOriginToCenter: function ()
|
||||
{
|
||||
this.originX = this.frame.centerX;
|
||||
this.originY = this.frame.centerY;
|
||||
this.setOrigin(0.5);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -22,14 +22,14 @@ var Texture = {
|
|||
{
|
||||
this.renderFlags |= _FLAG;
|
||||
|
||||
if (this.hasOwnProperty('originX'))
|
||||
{
|
||||
// Default origin to the center
|
||||
var w = Math.floor(this.frame.realWidth / 2);
|
||||
var h = Math.floor(this.frame.realHeight / 2);
|
||||
// if (this.hasOwnProperty('originX'))
|
||||
// {
|
||||
// // Default origin to the center
|
||||
// var w = Math.floor(this.frame.realWidth / 2);
|
||||
// var h = Math.floor(this.frame.realHeight / 2);
|
||||
|
||||
this.setOrigin(w, h);
|
||||
}
|
||||
// this.setOrigin(w, h);
|
||||
// }
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
|
@ -16,7 +16,6 @@ var Text = new Class({
|
|||
Components.GetBounds,
|
||||
Components.Origin,
|
||||
Components.ScaleMode,
|
||||
Components.Size,
|
||||
Components.Transform,
|
||||
Components.Visible,
|
||||
TextRender
|
||||
|
@ -46,7 +45,7 @@ var Text = new Class({
|
|||
|
||||
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
|
||||
|
@ -62,6 +61,9 @@ var Text = new Class({
|
|||
|
||||
this.padding = { x: 0, y: 0 };
|
||||
|
||||
this.width = 1;
|
||||
this.height = 1;
|
||||
|
||||
if (text !== '')
|
||||
{
|
||||
this.updateText();
|
||||
|
@ -88,6 +90,9 @@ var Text = new Class({
|
|||
|
||||
var textSize = GetTextSize(this, size, lines);
|
||||
|
||||
this.width = textSize.width;
|
||||
this.height = textSize.height;
|
||||
|
||||
canvas.width = textSize.width * this.resolution;
|
||||
canvas.height = textSize.height * this.resolution;
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
|
|||
renderer.currentScaleMode = src.scaleMode;
|
||||
}
|
||||
|
||||
var dx = src.x - src.originX - camera.scrollX;
|
||||
var dy = src.y - src.originY - camera.scrollY;
|
||||
var dx = src.x - src.displayOriginX - camera.scrollX;
|
||||
var dy = src.y - src.displayOriginY - camera.scrollY;
|
||||
|
||||
var canvas = src.canvas;
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ var DrawImage = function (src, camera)
|
|||
// ctx[this.smoothProperty] = (source.scaleMode === ScaleModes.LINEAR);
|
||||
}
|
||||
|
||||
var dx = frame.x - src.originX;
|
||||
var dy = frame.y - src.originY;
|
||||
var dx = frame.x - src.displayOriginX;
|
||||
var dy = frame.y - src.displayOriginY;
|
||||
|
||||
ctx.save();
|
||||
ctx.translate(src.x - camera.scrollX, src.y - camera.scrollY);
|
||||
|
|
|
@ -197,8 +197,8 @@ SpriteBatch.prototype = {
|
|||
var scaleY = src.scaleY;
|
||||
var rotation = -src.rotation;
|
||||
var tempMatrixMatrix = tempMatrix.matrix;
|
||||
var x = -src.originX + frame.x;
|
||||
var y = -src.originY + frame.y;
|
||||
var x = -src.displayOriginX + frame.x;
|
||||
var y = -src.displayOriginY + frame.y;
|
||||
var xw = x + width;
|
||||
var yh = y + height;
|
||||
var cameraMatrix = camera.matrix.matrix;
|
||||
|
|
Loading…
Reference in a new issue