Skip to content

Commit 89fe285

Browse files
committed
Fixed a few things in Circle and added the Point object.
1 parent 0f58945 commit 89fe285

4 files changed

Lines changed: 429 additions & 8 deletions

File tree

examples/point.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a(nother) new beginning</title>
5+
<script src="../src/Phaser.js"></script>
6+
<script src="../src/system/Device.js"></script>
7+
<script src="../src/core/SignalBinding.js"></script>
8+
<script src="../src/core/Signal.js"></script>
9+
<script src="../src/math/RandomDataGenerator.js"></script>
10+
<script src="../src/math/Math.js"></script>
11+
<script src="../src/geom/Point.js"></script>
12+
<script src="../src/geom/Circle.js"></script>
13+
<script src="../src/net/Net.js"></script>
14+
<script src="../src/time/Time.js"></script>
15+
<script src="../src/animation/Animation.js"></script>
16+
<script src="../src/animation/Frame.js"></script>
17+
<script src="../src/animation/FrameData.js"></script>
18+
<script src="../src/animation/Parser.js"></script>
19+
<script src="../src/loader/Cache.js"></script>
20+
<script src="../src/loader/Loader.js"></script>
21+
<script src="../src/Game.js"></script>
22+
</head>
23+
<body>
24+
25+
<script type="text/javascript">
26+
27+
var game = new Phaser.Game(this, '', 800, 600);
28+
29+
var a = new Phaser.Point(100, 100);
30+
var b = new Phaser.Point(200, 100);
31+
32+
console.log('Point A', a.toString());
33+
console.log('Point B', b.toString());
34+
35+
a.add(b.x, b.y);
36+
37+
console.log('Point A + B', a.toString());
38+
39+
console.log('Distance between A and B', Phaser.Point.distance(a, b));
40+
41+
</script>
42+
43+
</body>
44+
</html>

examples/wip1.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="../src/core/Signal.js"></script>
99
<script src="../src/math/RandomDataGenerator.js"></script>
1010
<script src="../src/math/Math.js"></script>
11+
<script src="../src/geom/Point.js"></script>
1112
<script src="../src/geom/Circle.js"></script>
1213
<script src="../src/net/Net.js"></script>
1314
<script src="../src/time/Time.js"></script>
@@ -25,16 +26,17 @@
2526

2627
var game = new Phaser.Game(this, '', 800, 600);
2728

28-
var data = Phaser.Math.sinCosGenerator(10);
29+
var a = new Phaser.Point(100, 100);
30+
var b = new Phaser.Point(200, 100);
2931

30-
console.log('Sin', data.sin);
31-
console.log('Cos', data.cos);
32+
console.log('Point A', a.toString());
33+
console.log('Point B', b.toString());
3234

33-
console.log('Shift value 1', Phaser.Math.shift(data.sin));
34-
console.log('Shift value 2', Phaser.Math.shift(data.sin));
35-
console.log('Shift value 3', Phaser.Math.shift(data.sin));
35+
a.add(b.x, b.y);
3636

37-
console.log('Sin', data.sin);
37+
console.log('Point A + B', a.toString());
38+
39+
console.log('Distance between A and B', Phaser.Point.distance(a, b));
3840

3941
</script>
4042

src/geom/Circle.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,18 @@ Phaser.Circle.prototype = {
9494
* @param {bool} [optional] round Round the distance to the nearest integer (default false)
9595
* @return {Number} The distance between this Point object and the destination Point object.
9696
*/
97-
distance: function () {
97+
distance: function (dest, round) {
98+
99+
if (typeof round === "undefined") { round = false }
100+
101+
if (round)
102+
{
103+
return Phaser.Math.distanceRound(this.x, this.y, dest.x, dest.y);
104+
}
105+
else
106+
{
107+
return Phaser.Math.distance(this.x, this.y, dest.x, dest.y);
108+
}
98109

99110
},
100111

0 commit comments

Comments
 (0)