Skip to content

Commit 6bfe450

Browse files
committed
Added getTopLeft, getTopRight, getBottomLeft and getBottomRight to GetBounds component
1 parent f70e343 commit 6bfe450

1 file changed

Lines changed: 74 additions & 2 deletions

File tree

v3/src/gameobjects/components/GetBounds.js

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,84 @@
11
var Rectangle = require('../../geom/rectangle/Rectangle');
2+
var RotateAround = require('../../math/RotateAround');
3+
var Vector2 = require('../../math/Vector2');
24

35
var GetBounds = {
46

7+
getTopLeft: function (output)
8+
{
9+
if (output === undefined) { output = new Vector2(); }
10+
11+
output.x = this.x - (this.displayWidth * this.originX);
12+
output.y = this.y - (this.displayHeight * this.originY);
13+
14+
if (this.rotation !== 0)
15+
{
16+
RotateAround(output, this.x, this.y, this.rotation);
17+
}
18+
19+
return output;
20+
},
21+
22+
getTopRight: function (output)
23+
{
24+
if (output === undefined) { output = new Vector2(); }
25+
26+
output.x = (this.x - (this.displayWidth * this.originX)) + this.displayWidth;
27+
output.y = this.y - (this.displayHeight * this.originY);
28+
29+
if (this.rotation !== 0)
30+
{
31+
RotateAround(output, this.x, this.y, this.rotation);
32+
}
33+
34+
return output;
35+
},
36+
37+
getBottomLeft: function (output)
38+
{
39+
if (output === undefined) { output = new Vector2(); }
40+
41+
output.x = this.x - (this.displayWidth * this.originX);
42+
output.y = (this.y - (this.displayHeight * this.originY)) + this.displayHeight;
43+
44+
if (this.rotation !== 0)
45+
{
46+
RotateAround(output, this.x, this.y, this.rotation);
47+
}
48+
49+
return output;
50+
},
51+
52+
getBottomRight: function (output)
53+
{
54+
if (output === undefined) { output = new Vector2(); }
55+
56+
output.x = (this.x - (this.displayWidth * this.originX)) + this.displayWidth;
57+
output.y = (this.y - (this.displayHeight * this.originY)) + this.displayHeight;
58+
59+
if (this.rotation !== 0)
60+
{
61+
RotateAround(output, this.x, this.y, this.rotation);
62+
}
63+
64+
return output;
65+
},
66+
567
getBounds: function (output)
668
{
769
if (output === undefined) { output = new Rectangle(); }
870

9-
var x = this.x - this.displayOriginX;
10-
var y = this.y - this.displayOriginY;
71+
var tmp = new Vector2();
72+
73+
this.getTopLeft(tmp);
74+
75+
var topRight = this.getTopRight();
76+
var bottomLeft = this.getBottomLeft();
77+
var bottomRight = this.getBottomRight();
78+
79+
/*
80+
var x = this.x;
81+
var y = this.y;
1182
1283
var w = this.displayWidth;
1384
var h = this.displayHeight;
@@ -61,6 +132,7 @@ var GetBounds = {
61132
output.y = yMin;
62133
output.width = xMax - xMin;
63134
output.height = yMax - yMin;
135+
*/
64136

65137
return output;
66138
}

0 commit comments

Comments
 (0)