Skip to content

Commit 31c4d8c

Browse files
committed
Adding in missing tests and fixing as we go
1 parent d510b78 commit 31c4d8c

30 files changed

Lines changed: 529 additions & 118 deletions

Phaser/components/sprite/Texture.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module Phaser.Components {
143143
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
144144
* @return {Sprite} Sprite instance itself.
145145
*/
146-
public loadImage(key: string, clearAnimations: bool = true) {
146+
public loadImage(key: string, clearAnimations?: bool = true, updateBody?: bool = true) {
147147

148148
if (clearAnimations && this._sprite.animations.frameData !== null)
149149
{
@@ -163,6 +163,12 @@ module Phaser.Components {
163163
this._sprite.frameBounds.width = this.width;
164164
this._sprite.frameBounds.height = this.height;
165165
}
166+
167+
if (updateBody)
168+
{
169+
this._sprite.body.bounds.width = this.width;
170+
this._sprite.body.bounds.height = this.height;
171+
}
166172
}
167173

168174
}

Phaser/core/Group.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,18 @@ module Phaser {
201201

202202
if (this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false)
203203
{
204-
this._member.render.call(renderer, camera, this._member);
204+
//this._member.render.call(renderer, camera, this._member);
205+
// call = context first, then parameters
206+
if (this._member.type == Types.GROUP)
207+
{
208+
//console.log('group rend');
209+
this._member.render.call(this._member, renderer, camera, this._member);
210+
//this._member.render.call(this, renderer, camera, this._member);
211+
}
212+
else
213+
{
214+
this._member.render.call(renderer, camera, this._member);
215+
}
205216
}
206217
}
207218

Phaser/gameobjects/Emitter.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ module Phaser {
4646
this._explode = true;
4747
this.on = false;
4848

49+
this.exists = true;
50+
this.active = true;
51+
this.visible = true;
52+
4953
}
5054

5155
/**
@@ -73,6 +77,11 @@ module Phaser {
7377
*/
7478
public alive: bool;
7579

80+
/**
81+
*
82+
*/
83+
public active: bool;
84+
7685
/**
7786
* The minimum possible velocity of a particle.
7887
* The default value is (-100,-100).
@@ -217,29 +226,14 @@ module Phaser {
217226
{
218227
/*
219228
randomFrame = this.game.math.random()*totalFrames;
220-
if(BakedRotations > 0)
221-
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
222-
else
223-
{
224-
particle.loadGraphic(Graphics,true);
225-
particle.frame = randomFrame;
226-
}
227229
*/
228230
}
229231
else
230232
{
231-
/*
232-
if (BakedRotations > 0)
233-
particle.loadRotatedGraphic(Graphics,BakedRotations);
234-
else
235-
particle.loadGraphic(Graphics);
236-
*/
237-
238233
if (graphics)
239234
{
240235
particle.texture.loadImage(graphics);
241236
}
242-
243237
}
244238

245239
if (collide > 0)
@@ -255,6 +249,8 @@ module Phaser {
255249
}
256250

257251
particle.exists = false;
252+
// Center the origin for rotation assistance
253+
particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
258254

259255
this.add(particle);
260256

@@ -264,6 +260,9 @@ module Phaser {
264260
return this;
265261
}
266262

263+
public preUpdate() { }
264+
public postUpdate() { }
265+
267266
/**
268267
* Called automatically by the game loop, decides when to launch particles and when to "die".
269268
*/

Phaser/gameobjects/Particle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Phaser {
2020

2121
super(game);
2222

23+
this.body.type = Types.BODY_DYNAMIC;
2324
this.lifespan = 0;
2425
this.friction = 500;
2526

@@ -45,7 +46,7 @@ module Phaser {
4546
*/
4647
public update() {
4748

48-
//lifespan behavior
49+
// Lifespan behavior
4950
if (this.lifespan <= 0)
5051
{
5152
return;

Phaser/math/QuadTree.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ module Phaser {
2323
* @param {Number} height Desired height of this node.
2424
* @param {Number} parent The parent branch or node. Pass null to create a root.
2525
*/
26-
constructor(x: number, y: number, width: number, height: number, parent: QuadTree = null) {
26+
constructor(manager: Phaser.Physics.PhysicsManager, x: number, y: number, width: number, height: number, parent: QuadTree = null) {
2727

2828
super(x, y, width, height);
2929

30+
QuadTree.physics = manager;
31+
3032
this._headA = this._tailA = new Phaser.LinkedList();
3133
this._headB = this._tailB = new Phaser.LinkedList();
3234

@@ -102,6 +104,8 @@ module Phaser {
102104
private _overlapProcessed: bool;
103105
private _checkObject;
104106

107+
public static physics: Phaser.Physics.PhysicsManager;
108+
105109
/**
106110
* Flag for specifying that you want to add an object to the A list.
107111
*/
@@ -392,7 +396,7 @@ module Phaser {
392396
{
393397
if (this._northWestTree == null)
394398
{
395-
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
399+
this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
396400
}
397401

398402
this._northWestTree.addObject();
@@ -403,7 +407,7 @@ module Phaser {
403407
{
404408
if (this._southWestTree == null)
405409
{
406-
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
410+
this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
407411
}
408412

409413
this._southWestTree.addObject();
@@ -417,7 +421,7 @@ module Phaser {
417421
{
418422
if (this._northEastTree == null)
419423
{
420-
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
424+
this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
421425
}
422426

423427
this._northEastTree.addObject();
@@ -428,7 +432,7 @@ module Phaser {
428432
{
429433
if (this._southEastTree == null)
430434
{
431-
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
435+
this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
432436
}
433437

434438
this._southEastTree.addObject();
@@ -441,7 +445,7 @@ module Phaser {
441445
{
442446
if (this._northWestTree == null)
443447
{
444-
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
448+
this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
445449
}
446450

447451
this._northWestTree.addObject();
@@ -451,7 +455,7 @@ module Phaser {
451455
{
452456
if (this._northEastTree == null)
453457
{
454-
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
458+
this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
455459
}
456460

457461
this._northEastTree.addObject();
@@ -461,7 +465,7 @@ module Phaser {
461465
{
462466
if (this._southEastTree == null)
463467
{
464-
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
468+
this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
465469
}
466470

467471
this._southEastTree.addObject();
@@ -471,7 +475,7 @@ module Phaser {
471475
{
472476
if (this._southWestTree == null)
473477
{
474-
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
478+
this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
475479
}
476480

477481
this._southWestTree.addObject();
@@ -621,7 +625,8 @@ module Phaser {
621625
continue;
622626
}
623627

624-
if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds))
628+
//if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds))
629+
if (QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body))
625630
{
626631
//Execute callback functions if they exist
627632
if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject))

Phaser/physics/PhysicsManager.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module Phaser.Physics {
139139
return;
140140
}
141141

142-
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
142+
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
143143
body.angularVelocity += this._velocityDelta;
144144
body.angle += body.angularVelocity * this.game.time.elapsed;
145145
body.angularVelocity += this._velocityDelta;
@@ -225,19 +225,8 @@ module Phaser.Physics {
225225

226226
}
227227

228-
private checkHullIntersection(body1: Body, body2:Body): bool {
229-
228+
public checkHullIntersection(body1: Body, body2:Body): bool {
230229
return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight));
231-
232-
//if ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight))
233-
//{
234-
// return true;
235-
//}
236-
//else
237-
//{
238-
// return false;
239-
//}
240-
241230
}
242231

243232
/**
@@ -753,7 +742,7 @@ module Phaser.Physics {
753742

754743
QuadTree.divisions = this.worldDivisions;
755744

756-
this._quadTree = new QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
745+
this._quadTree = new QuadTree(this, this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
757746

758747
this._quadTree.load(object1, object2, notifyCallback, processCallback, context);
759748

Phaser/utils/SpriteUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ module Phaser {
278278
sprite.y = y;
279279
sprite.body.velocity.x = 0;
280280
sprite.body.velocity.y = 0;
281+
sprite.body.position.x = x;
282+
sprite.body.position.y = y;
281283

282284
}
283285

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ TODO:
2828
* Copy the setTransform from Sprite to Camera
2929
* Move Camera.scroll.x to just Camera.x/y
3030
* Apply Sprite scaling to Body.bounds
31+
* When you modify the sprite x/y directly the body position doesn't update, which leads to weird results. Need to work out who controls who.
32+
3133

3234

3335
V1.0.0

Tests/Tests.csproj

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@
6666
<DependentUpon>scrollfactor 2.ts</DependentUpon>
6767
</Content>
6868
<TypeScriptCompile Include="physics\aabb 1.ts" />
69+
<TypeScriptCompile Include="particles\graphic emitter.ts" />
70+
<Content Include="particles\graphic emitter.js">
71+
<DependentUpon>graphic emitter.ts</DependentUpon>
72+
</Content>
73+
<TypeScriptCompile Include="particles\multiple streams.ts" />
74+
<Content Include="particles\multiple streams.js">
75+
<DependentUpon>multiple streams.ts</DependentUpon>
76+
</Content>
77+
<TypeScriptCompile Include="particles\sprite emitter.ts" />
78+
<Content Include="particles\sprite emitter.js">
79+
<DependentUpon>sprite emitter.ts</DependentUpon>
80+
</Content>
81+
<TypeScriptCompile Include="particles\when particles collide.ts" />
82+
<Content Include="particles\when particles collide.js">
83+
<DependentUpon>when particles collide.ts</DependentUpon>
84+
</Content>
6985
<Content Include="physics\aabb 1.js">
7086
<DependentUpon>aabb 1.ts</DependentUpon>
7187
</Content>
@@ -158,8 +174,6 @@
158174
<DependentUpon>boot screen.ts</DependentUpon>
159175
</Content>
160176
</ItemGroup>
161-
<ItemGroup>
162-
<Folder Include="particles\" />
163-
</ItemGroup>
177+
<ItemGroup />
164178
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
165179
</Project>

Tests/particles/graphic emitter.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="../../Phaser/Game.ts" />
2+
(function () {
3+
var game = new Phaser.Game(this, 'game', 800, 600, init, create);
4+
var emitter;
5+
function init() {
6+
game.loader.addImageFile('jet', 'assets/sprites/jets.png');
7+
game.loader.load();
8+
}
9+
function create() {
10+
emitter = game.add.emitter(game.stage.centerX, game.stage.centerY);
11+
emitter.makeParticles('jet', 50, false, 0);
12+
emitter.start(false, 10, 0.1);
13+
}
14+
})();

0 commit comments

Comments
 (0)