Skip to content

Commit 3d0b5bd

Browse files
committed
Updated World vastly. No longer extends p2.World due to a few vars we can't alias cleanly, adds in lots of new helper methods.
Ready for Materials and Constraints. InversePointProxy is for aliasing a p2 typed array when the values need reversing before applying (gravity for example).
1 parent 335684a commit 3d0b5bd

6 files changed

Lines changed: 761 additions & 204 deletions

File tree

Gruntfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ module.exports = function (grunt) {
135135

136136
'src/physics/World.js',
137137
'src/physics/PointProxy.js',
138+
'src/physics/InversePointProxy.js',
138139
'src/physics/Body.js',
139140
'src/physics/Spring.js',
141+
'src/physics/Material.js',
140142

141143
'src/particles/Particles.js',
142144
'src/particles/arcade/ArcadeParticles.js',

build/config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@
181181
182182
<script src="$path/src/physics/World.js"></script>
183183
<script src="$path/src/physics/PointProxy.js"></script>
184+
<script src="$path/src/physics/InversePointProxy.js"></script>
184185
<script src="$path/src/physics/Body.js"></script>
185186
<script src="$path/src/physics/Spring.js"></script>
187+
<script src="$path/src/physics/Material.js"></script>
186188
187189
<script src="$path/src/particles/Particles.js"></script>
188190
<script src="$path/src/particles/arcade/ArcadeParticles.js"></script>

src/physics/Body.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Phaser.Physics.Body = function (game, sprite, x, y, mass) {
7070
if (sprite)
7171
{
7272
this.setRectangleFromSprite(sprite);
73-
this.game.physics.addBody(this.data);
73+
this.game.physics.addBody(this);
7474
}
7575

7676
};
@@ -399,7 +399,7 @@ Phaser.Physics.Body.prototype = {
399399

400400
if (this.data.world !== this.game.physics)
401401
{
402-
this.game.physics.addBody(this.data);
402+
this.game.physics.addBody(this);
403403
}
404404

405405
},

src/physics/InversePointProxy.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2014 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* A InversePointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays but inverses the values on set.
9+
*
10+
* @class Phaser.Physics.InversePointProxy
11+
* @classdesc InversePointProxy
12+
* @constructor
13+
* @param {any} destination - The object to bind to.
14+
*/
15+
Phaser.Physics.InversePointProxy = function (destination) {
16+
17+
this.destination = destination;
18+
19+
};
20+
21+
Phaser.Physics.InversePointProxy.prototype.constructor = Phaser.Physics.InversePointProxy;
22+
23+
/**
24+
* @name Phaser.Physics.InversePointProxy#x
25+
* @property {number} x - The x property of this InversePointProxy.
26+
*/
27+
Object.defineProperty(Phaser.Physics.InversePointProxy.prototype, "x", {
28+
29+
get: function () {
30+
31+
return this.destination[0];
32+
33+
},
34+
35+
set: function (value) {
36+
37+
this.destination[0] *= -value;
38+
39+
}
40+
41+
});
42+
43+
/**
44+
* @name Phaser.Physics.InversePointProxy#y
45+
* @property {number} y - The y property of this InversePointProxy.
46+
*/
47+
Object.defineProperty(Phaser.Physics.InversePointProxy.prototype, "y", {
48+
49+
get: function () {
50+
51+
return this.destination[1];
52+
53+
},
54+
55+
set: function (value) {
56+
57+
this.destination[1] *= -value;
58+
59+
}
60+
61+
});

src/physics/Material.js

Whitespace-only changes.

0 commit comments

Comments
 (0)