Skip to content

Commit 3f3b6bf

Browse files
committed
Brand new highly optimised QuadTree added, populated by the game loop and world ready to be queried as often as you want in your game loop, without creating hundreds of new QuadTrees each frame.
1 parent 2a353a0 commit 3f3b6bf

8 files changed

Lines changed: 362 additions & 83 deletions

File tree

examples/js.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<script src="../src/system/RequestAnimationFrame.js"></script>
6969
<script src="../src/math/RandomDataGenerator.js"></script>
7070
<script src="../src/math/Math.js"></script>
71+
<script src="../src/math/QuadTree.js"></script>
7172
<script src="../src/geom/Circle.js"></script>
7273
<script src="../src/geom/Point.js"></script>
7374
<script src="../src/geom/Rectangle.js"></script>

examples/quadtree.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
</head>
9+
<body>
10+
11+
<script type="text/javascript">
12+
13+
(function () {
14+
15+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
16+
17+
function preload() {
18+
game.load.image('ship', 'assets/sprites/xenon2_ship.png');
19+
game.load.image('baddie', 'assets/sprites/space-baddie.png');
20+
}
21+
22+
var ship;
23+
24+
function create() {
25+
26+
for (var i = 0; i < 50; i++)
27+
{
28+
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddie');
29+
s.body.collideWorldBounds = true;
30+
s.body.bounce.setTo(1, 1);
31+
s.body.velocity.setTo(50 + Math.random() * 50, 50 + Math.random() * 50);
32+
}
33+
34+
ship = game.add.sprite(400, 400, 'ship');
35+
ship.body.collideWorldBounds = true;
36+
ship.body.bounce.setTo(0.5, 0.5);
37+
38+
}
39+
40+
function update() {
41+
42+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
43+
{
44+
ship.body.velocity.x -= 2;
45+
}
46+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
47+
{
48+
ship.body.velocity.x += 2;
49+
}
50+
51+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
52+
{
53+
ship.body.velocity.y -= 2;
54+
}
55+
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
56+
{
57+
ship.body.velocity.y += 2;
58+
}
59+
60+
}
61+
62+
function render() {
63+
64+
65+
}
66+
67+
})();
68+
69+
</script>
70+
71+
</body>
72+
</html>

src/core/Game.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,20 @@ Phaser.Game.prototype = {
376376
this.time.update(time);
377377

378378
this.plugins.preUpdate();
379+
this.physics.preUpdate();
379380

380381
this.input.update();
381382
this.tweens.update();
382383
this.sound.update();
383384
this.world.update();
384385
this.state.update();
385-
// this.physics.update();
386386
this.plugins.update();
387387

388388
this.renderer.render(this.world._stage);
389389
this.state.render();
390390

391391
this.world.postUpdate();
392+
this.physics.postUpdate();
392393

393394
this.plugins.postRender();
394395

src/core/World.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Phaser.World.prototype = {
5353

5454
var displayObject = this._stage;
5555

56-
// once the display object hits this. we can break the loop
5756
var testObject = displayObject.last._iNext;
5857
displayObject = displayObject.first;
5958

@@ -73,11 +72,8 @@ Phaser.World.prototype = {
7372

7473
postUpdate: function () {
7574

76-
//this.camera.update();
77-
7875
var displayObject = this._stage;
7976

80-
// once the display object hits this. we can break the loop
8177
var testObject = displayObject.last._iNext;
8278
displayObject = displayObject.first;
8379

src/math/LinkedList.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)