Skip to content

Commit e88b103

Browse files
committed
Updated Phaser geometry classes so they over-ride the PIXI native ones, means we can do away with a whole bunch of over-rides and object changes in Sprite, etc.
1 parent 8eae8fe commit e88b103

6 files changed

Lines changed: 173 additions & 41 deletions

File tree

build/config.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
<script src="$path/src/pixi/extras/Spine.js"></script>
3939
4040
<script src="$path/src/pixi/utils/Utils.js"></script>
41+
42+
<script src="$path/src/pixi/core/Point.js"></script>
43+
<script src="$path/src/pixi/core/Rectangle.js"></script>
44+
<script src="$path/src/pixi/core/Circle.js"></script>
45+
46+
<script src="$path/src/pixi/utils/Detector.js"></script>
4147
4248
*/
4349

@@ -48,11 +54,13 @@
4854
<script src="$path/src/Phaser.js"></script>
4955
<script src="$path/src/utils/Utils.js"></script>
5056
57+
<script src="$path/src/geom/Circle.js"></script>
58+
<script src="$path/src/geom/Point.js"></script>
59+
<script src="$path/src/geom/Rectangle.js"></script>
60+
<script src="$path/src/geom/Line.js"></script>
61+
5162
<script src="$path/src/pixi/Pixi.js"></script>
52-
<script src="$path/src/pixi/core/Point.js"></script>
53-
<script src="$path/src/pixi/core/Rectangle.js"></script>
5463
<script src="$path/src/pixi/core/Polygon.js"></script>
55-
<script src="$path/src/pixi/core/Circle.js"></script>
5664
<script src="$path/src/pixi/core/Ellipse.js"></script>
5765
<script src="$path/src/pixi/core/Matrix.js"></script>
5866
<script src="$path/src/pixi/display/DisplayObject.js"></script>
@@ -65,7 +73,6 @@
6573
<script src="$path/src/pixi/text/BitmapText.js"></script>
6674
<script src="$path/src/pixi/display/Stage.js"></script>
6775
<script src="$path/src/pixi/utils/EventTarget.js"></script>
68-
<script src="$path/src/pixi/utils/Detector.js"></script>
6976
<script src="$path/src/pixi/utils/Polyk.js"></script>
7077
<script src="$path/src/pixi/renderers/webgl/utils/WebGLShaderUtils.js"></script>
7178
<script src="$path/src/pixi/renderers/webgl/shaders/PixiShader.js"></script>
@@ -138,10 +145,6 @@
138145
<script src="$path/src/math/Math.js"></script>
139146
<script src="$path/src/math/QuadTree.js"></script>
140147
141-
<script src="$path/src/geom/Circle.js"></script>
142-
<script src="$path/src/geom/Point.js"></script>
143-
<script src="$path/src/geom/Rectangle.js"></script>
144-
<script src="$path/src/geom/Line.js"></script>
145148
146149
<script src="$path/src/net/Net.js"></script>
147150

examples/wip/pixi1.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function preload() {
1010
var sprite;
1111
var sprite2;
1212
var g;
13+
var p;
1314

1415
function create() {
1516

@@ -28,6 +29,8 @@ function create() {
2829

2930
game.add.tween(sprite).to({y: 500}, 3000, Phaser.Easing.Linear.None, true);
3031

32+
p = new PIXI.Point(43, 45);
33+
3134
}
3235

3336
function tint() {

src/Phaser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var Phaser = Phaser || {
4444
CANVAS_PX_ROUND: false,
4545
CANVAS_CLEAR_RECT: true
4646

47-
};
47+
};
4848

4949
PIXI.InteractionManager = function (dummy) {
5050
// We don't need this in Pixi, so we've removed it to save space

src/geom/Circle.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,16 @@ Phaser.Circle.prototype = {
132132
*/
133133
clone: function(out) {
134134

135-
if (typeof out === "undefined") { out = new Phaser.Circle(); }
135+
if (typeof out === "undefined")
136+
{
137+
out = new Phaser.Circle(this.x, this.y, this.diameter);
138+
}
139+
else
140+
{
141+
out.setTo(this.x, this.y, this.diameter);
142+
}
136143

137-
return out.setTo(this.x, this.y, this.diameter);
144+
return out;
138145

139146
},
140147

@@ -377,14 +384,18 @@ Object.defineProperty(Phaser.Circle.prototype, "empty", {
377384
*/
378385
Phaser.Circle.contains = function (a, x, y) {
379386

380-
// Check if x/y are within the bounds first
381-
if (x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
387+
if (a.radius <= 0)
388+
{
389+
return false;
390+
}
382391

392+
// Check if x/y are within the bounds first
393+
if (x >= a.left && x <= a.right && y >= a.top && y <= a.bottom)
394+
{
383395
var dx = (a.x - x) * (a.x - x);
384396
var dy = (a.y - y) * (a.y - y);
385397

386398
return (dx + dy) <= (a.radius * a.radius);
387-
388399
}
389400

390401
return false;
@@ -475,3 +486,6 @@ Phaser.Circle.intersectsRectangle = function (c, r) {
475486
return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
476487

477488
};
489+
490+
// Because PIXI uses its own Circle, we'll replace it with ours to avoid duplicating code or confusion.
491+
PIXI.Circle = Phaser.Circle;

src/geom/Point.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,25 @@ Phaser.Point.prototype = {
5959
*/
6060
setTo: function (x, y) {
6161

62-
this.x = x;
63-
this.y = y;
62+
this.x = x || 0;
63+
this.y = y || ( (y !== 0) ? this.x : 0 );
64+
65+
return this;
66+
67+
},
68+
69+
/**
70+
* Sets the x and y values of this Point object to the given coordinates.
71+
* @method Phaser.Point#set
72+
* @param {number} x - The horizontal position of this point.
73+
* @param {number} y - The vertical position of this point.
74+
* @return {Point} This Point object. Useful for chaining method calls.
75+
*/
76+
set: function (x, y) {
77+
78+
this.x = x || 0;
79+
this.y = y || ( (y !== 0) ? this.x : 0 );
80+
6481
return this;
6582

6683
},
@@ -176,9 +193,16 @@ Phaser.Point.prototype = {
176193
*/
177194
clone: function (output) {
178195

179-
if (typeof output === "undefined") { output = new Phaser.Point(); }
196+
if (typeof output === "undefined")
197+
{
198+
output = new Phaser.Point(this.x, this.y);
199+
}
200+
else
201+
{
202+
output.setTo(this.x, this.y);
203+
}
180204

181-
return output.setTo(this.x, this.y);
205+
return output;
182206

183207
},
184208

@@ -430,3 +454,6 @@ Phaser.Point.rotate = function (a, x, y, angle, asDegrees, distance) {
430454
return a.setTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
431455

432456
};
457+
458+
// Because PIXI uses its own Point, we'll replace it with ours to avoid duplicating code or confusion.
459+
PIXI.Point = Phaser.Point;

0 commit comments

Comments
 (0)