Skip to content

Commit be05610

Browse files
committed
Removed redundant render vars and Origin method.
1 parent 22154d9 commit be05610

6 files changed

Lines changed: 26 additions & 17 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '867d0fc0-09d0-11e7-a41f-615c7733ee76'
2+
build: 'd4e14b10-09d8-11e7-baf9-7d39f1ceeee3'
33
};
44
module.exports = CHECKSUM;

v3/src/components/Origin.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Origin Component
2-
// Values are given in pixels, not percent
2+
// Values are normalized, given in the range 0 to 1.
3+
// Display values contain the calculated pixel values.
34

45
var Origin = {
56

@@ -18,15 +19,15 @@ var Origin = {
1819
this.originX = x;
1920
this.originY = y;
2021

21-
this.displayOriginX = x * this.width;
22-
this.displayOriginY = y * this.height;
23-
24-
return this;
22+
return this.updateOrigin();
2523
},
2624

27-
setOriginToCenter: function ()
25+
updateOrigin: function ()
2826
{
29-
this.setOrigin(0.5);
27+
this.displayOriginX = this.originX * this.width;
28+
this.displayOriginY = this.originY * this.height;
29+
30+
return this;
3031
}
3132

3233
};

v3/src/gameobjects/image/Image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Image = new Class({
2828
this.setTexture(texture, frame);
2929
this.setPosition(x, y);
3030
this.setSizeToFrame();
31-
this.setOriginToCenter();
31+
this.setOrigin();
3232
}
3333

3434
});

v3/src/gameobjects/sprite/Sprite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Sprite = new Class({
2828
this.setTexture(texture, frame);
2929
this.setPosition(x, y);
3030
this.setSizeToFrame();
31-
this.setOriginToCenter();
31+
this.setOrigin();
3232
}
3333

3434
});

v3/src/gameobjects/text/static/Text.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ var Text = new Class({
7070
}
7171
},
7272

73+
setText: function (value)
74+
{
75+
if (value !== this.text)
76+
{
77+
this.text = value;
78+
this.updateText();
79+
}
80+
81+
return this;
82+
},
83+
7384
updateText: function ()
7485
{
7586
var canvas = this.canvas;
@@ -93,6 +104,8 @@ var Text = new Class({
93104
this.width = textSize.width;
94105
this.height = textSize.height;
95106

107+
this.updateOrigin();
108+
96109
canvas.width = textSize.width * this.resolution;
97110
canvas.height = textSize.height * this.resolution;
98111

v3/src/gameobjects/text/static/TextCanvasRenderer.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
2727
renderer.currentScaleMode = src.scaleMode;
2828
}
2929

30-
var dx = src.x - src.displayOriginX - camera.scrollX;
31-
var dy = src.y - src.displayOriginY - camera.scrollY;
32-
3330
var canvas = src.canvas;
3431

3532
ctx.save();
36-
ctx.translate(src.x, src.y);
33+
ctx.translate(src.x - camera.scrollX, src.y - camera.scrollY);
3734
ctx.rotate(src.rotation);
3835
ctx.scale(src.scaleX, src.scaleY);
39-
40-
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, dx, dy, canvas.width, canvas.height);
41-
36+
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, -src.displayOriginX, -src.displayOriginY, canvas.width, canvas.height);
4237
ctx.restore();
4338
};
4439

0 commit comments

Comments
 (0)