Skip to content

Commit f2054f8

Browse files
committed
Physics shape offset now finally working
1 parent 0fad46e commit f2054f8

12 files changed

Lines changed: 2189 additions & 2034 deletions

File tree

Phaser/Phaser.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113
<Content Include="physics\AABB.js">
114114
<DependentUpon>AABB.ts</DependentUpon>
115115
</Content>
116+
<TypeScriptCompile Include="physics\IPhysicsShape.ts" />
117+
<Content Include="physics\IPhysicsShape.js">
118+
<DependentUpon>IPhysicsShape.ts</DependentUpon>
119+
</Content>
116120
<Content Include="physics\PhysicsManager.js">
117121
<DependentUpon>PhysicsManager.ts</DependentUpon>
118122
</Content>

Phaser/components/sprite/Physics.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ module Phaser.Components {
1717
this._game = parent.game;
1818
this._sprite = parent;
1919

20-
this.gravityFactor = new Vec2(1, 1);
21-
this.drag = new Vec2(0, 0);
22-
this.bounce = new Vec2(0, 0);
23-
this.friction = new Vec2(0.05, 0.05);
24-
this.velocity = new Vec2(0, 0);
25-
this.acceleration = new Vec2(0, 0);
20+
// Copy from PhysicsManager?
21+
this.gravity = new Vec2;
22+
this.drag = new Vec2;
23+
this.bounce = new Vec2;
24+
this.friction = new Vec2;
25+
this.velocity = new Vec2;
26+
this.acceleration = new Vec2;
2627

2728
//this.AABB = new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height);
28-
this.AABB = this._game.world.physics.add(new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
29+
this.shape = this._game.world.physics.add(new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
2930

3031
}
3132

@@ -39,7 +40,7 @@ module Phaser.Components {
3940
*/
4041
private _sprite: Sprite;
4142

42-
public AABB: Phaser.Physics.AABB;
43+
public shape: Phaser.Physics.IPhysicsShape;
4344

4445
/**
4546
* Whether this object will be moved by impacts with other objects or not.
@@ -53,25 +54,26 @@ module Phaser.Components {
5354
*/
5455
public moves: bool = true;
5556

56-
public gravityFactor: Vec2;
57+
public gravity: Vec2;
5758
public drag: Vec2;
5859
public bounce: Vec2;
5960
public friction: Vec2;
6061
public velocity: Vec2;
6162
public acceleration: Vec2;
6263

63-
6464
/**
6565
* Internal function for updating the position and speed of this object.
6666
*/
6767
public update() {
6868

6969
if (this.moves)
7070
{
71-
this._sprite.x = this.AABB.position.x - this.AABB.halfWidth;
72-
this._sprite.y = this.AABB.position.y - this.AABB.halfHeight;
73-
//this._sprite.x = this.AABB.position.x;
74-
//this._sprite.y = this.AABB.position.y;
71+
this._sprite.x = (this.shape.position.x - this.shape.bounds.halfWidth) - this.shape.offset.x;
72+
this._sprite.y = (this.shape.position.y - this.shape.bounds.halfHeight) - this.shape.offset.y;
73+
//this._sprite.x = (this.shape.position.x - this.shape.bounds.halfWidth);
74+
//this._sprite.y = (this.shape.position.y - this.shape.bounds.halfHeight);
75+
//this._sprite.x = (this.shape.position.x);
76+
//this._sprite.y = (this.shape.position.y);
7577
}
7678
}
7779

Phaser/gameobjects/Sprite.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ module Phaser {
4848
this.width = this.frameBounds.width;
4949
this.height = this.frameBounds.height;
5050

51-
this.physics = new Phaser.Components.Physics(this);
52-
5351
// Transform related (if we add any more then move to a component)
5452
this.origin = new Phaser.Vec2(0, 0);
5553
this.scale = new Phaser.Vec2(1, 1);
5654
this.skew = new Phaser.Vec2(0, 0);
5755

56+
this.physics = new Phaser.Components.Physics(this);
57+
this.physics.shape.physics = this.physics;
58+
5859
}
5960

6061
/**

0 commit comments

Comments
 (0)