forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrigin.js
More file actions
76 lines (55 loc) · 1.42 KB
/
Copy pathOrigin.js
File metadata and controls
76 lines (55 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Origin Component
// Values are normalized, given in the range 0 to 1.
// Display values contain the calculated pixel values.
var Origin = {
originX: 0.5,
originY: 0.5,
// READ ONLY
_displayOriginX: 0,
_displayOriginY: 0,
displayOriginX: {
get: function ()
{
return this._displayOriginX;
},
set: function (value)
{
this._displayOriginX = value;
this.originX = value / this.width;
}
},
displayOriginY: {
get: function ()
{
return this._displayOriginY;
},
set: function (value)
{
this._displayOriginY = value;
this.originY = value / this.height;
}
},
setOrigin: function (x, y)
{
if (x === undefined) { x = 0.5; }
if (y === undefined) { y = x; }
this.originX = x;
this.originY = y;
return this.updateDisplayOrigin();
},
setDisplayOrigin: function (x, y)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = x; }
this.displayOriginX = x;
this.displayOriginY = y;
return this;
},
updateDisplayOrigin: function ()
{
this._displayOriginX = Math.round(this.originX * this.width);
this._displayOriginY = Math.round(this.originY * this.height);
return this;
}
};
module.exports = Origin;