Skip to content

Commit 5d3fe89

Browse files
committed
Particle Emitter in and working. Nice and fast, and a lot more flexible than before.
1 parent 2ba6b4f commit 5d3fe89

11 files changed

Lines changed: 681 additions & 2 deletions

File tree

examples/js.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<script src="../src/gameobjects/Text.js"></script>
6666
<script src="../src/gameobjects/Button.js"></script>
6767
<script src="../src/gameobjects/Graphics.js"></script>
68+
<script src="../src/gameobjects/RenderTexture.js"></script>
6869
<script src="../src/system/Canvas.js"></script>
6970
<script src="../src/system/StageScaleMode.js"></script>
7071
<script src="../src/system/Device.js"></script>
@@ -93,3 +94,7 @@
9394

9495
<script src="../src/physics/arcade/ArcadePhysics.js"></script>
9596
<script src="../src/physics/arcade/Body.js"></script>
97+
98+
<script src="../src/particles/Particles.js"></script>
99+
<script src="../src/particles/arcade/ArcadeParticles.js"></script>
100+
<script src="../src/particles/arcade/Emitter.js"></script>

examples/particles.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.AUTO, '', { preload: preload, create: create, update: update, render: render });
16+
17+
var p;
18+
19+
function preload() {
20+
21+
game.load.image('carrot', 'assets/sprites/carrot.png');
22+
game.load.image('star', 'assets/misc/star_particle.png');
23+
game.load.image('diamond', 'assets/sprites/diamond.png');
24+
game.load.image('dude', 'assets/sprites/phaser-dude.png');
25+
game.load.image('coke', 'assets/sprites/cokecan.png');
26+
27+
}
28+
29+
function create() {
30+
31+
p = new Phaser.Particles.Arcade.Emitter(game, 200, 100, 500);
32+
33+
// p.width = 200;
34+
// p.height = 200;
35+
36+
p.makeParticles('diamond');
37+
38+
// Steady constant stream at 250ms delay and 10 seconds lifespan
39+
// p.start(false, 10000, 250, 100);
40+
41+
// p.start(true, 10000);
42+
43+
// explode, lifespan, frequency, quantity
44+
p.minParticleSpeed.setTo(-100, -100);
45+
p.maxParticleSpeed.setTo(100, -200);
46+
p.gravity = 10;
47+
p.start(false, 3000, 10);
48+
49+
game.add.tween(p).to({ emitX: 400 }, 1000, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
50+
51+
}
52+
53+
function update() {
54+
55+
p.update();
56+
57+
}
58+
59+
function render() {
60+
}
61+
62+
})();
63+
</script>
64+
65+
</body>
66+
</html>

examples/rendertexture.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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, render: render });
16+
17+
function preload() {
18+
19+
game.load.image('atari1', 'assets/sprites/atari130xe.png');
20+
21+
}
22+
23+
function create() {
24+
25+
// var tempSprite = game.add.sprite(game.world.randomX, game.world.randomY, game.rnd.pick(images));
26+
var renderTexture = new Phaser.RenderTexture(800, 600);
27+
28+
}
29+
30+
function render() {
31+
}
32+
33+
})();
34+
</script>
35+
36+
</body>
37+
</html>

src/core/Game.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ Phaser.Game.prototype = {
255255
*/
256256
debug: null,
257257

258+
/**
259+
* The Particle Manager
260+
* @type {Phaser.Particles}
261+
*/
262+
particles: null,
263+
258264
/**
259265
* Initialize engine sub modules and start the game.
260266
* @param parent {string} ID of parent Dom element.

src/core/Group.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,18 @@ Phaser.Group.prototype = {
450450
*/
451451
getFirstExists: function (state) {
452452

453-
state = state || true;
453+
if (typeof state !== 'boolean')
454+
{
455+
state = true;
456+
}
454457

455458
if (this._container.first._iNext)
456459
{
457460
var currentNode = this._container.first._iNext;
458461

459462
do
460463
{
461-
if (currentNode.exists == state)
464+
if (currentNode.exists === state)
462465
{
463466
return currentNode;
464467
}

src/gameobjects/RenderTexture.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Phaser.RenderTexture = function (game, width, height) {
2+
3+
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all
4+
this.exists = true;
5+
6+
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering
7+
this.alive = true;
8+
9+
this.group = null;
10+
11+
this.name = '';
12+
13+
this.game = game;
14+
15+
PIXI.EventTarget.call( this );
16+
17+
this.width = width || 100;
18+
this.height = height || 100;
19+
20+
this.indetityMatrix = PIXI.mat3.create();
21+
22+
this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
23+
24+
if (PIXI.gl)
25+
{
26+
this.initWebGL();
27+
}
28+
else
29+
{
30+
this.initCanvas();
31+
}
32+
33+
};
34+
35+
Phaser.RenderTexture.prototype = Phaser.Utils.extend(true, PIXI.RenderTexture.prototype);
36+
Phaser.RenderTexture.prototype.constructor = Phaser.RenderTexture;

src/gameobjects/Sprite.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Phaser.Sprite = function (game, x, y, key, frame) {
1919

2020
this.renderOrderID = -1;
2121

22+
// If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
23+
// The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
24+
this.lifespan = 0;
25+
2226
if (key)
2327
{
2428
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
@@ -164,6 +168,17 @@ Phaser.Sprite.prototype.update = function() {
164168
return;
165169
}
166170

171+
if (this.lifespan > 0)
172+
{
173+
this.lifespan -= this.game.time.elapsed;
174+
175+
if (this.lifespan <= 0)
176+
{
177+
this.kill();
178+
return;
179+
}
180+
}
181+
167182
this._cache.dirty = false;
168183

169184
if (this.animations.update())
@@ -275,14 +290,35 @@ Phaser.Sprite.prototype.update = function() {
275290

276291
}
277292

293+
Phaser.Sprite.prototype.revive = function() {
294+
295+
this.alive = true;
296+
this.exists = true;
297+
this.visible = true;
298+
this.events.onRevived.dispatch(this);
299+
300+
}
301+
302+
Phaser.Sprite.prototype.kill = function() {
303+
304+
this.alive = false;
305+
this.exists = false;
306+
this.visible = false;
307+
this.events.onKilled.dispatch(this);
308+
309+
}
310+
278311
Phaser.Sprite.prototype.reset = function(x, y) {
279312

280313
this.x = x;
281314
this.y = y;
315+
this.position.x = x;
316+
this.position.y = y;
282317
this.alive = true;
283318
this.exists = true;
284319
this.visible = true;
285320
this._outOfBoundsFired = false;
321+
this.body.reset();
286322

287323
}
288324

src/particles/Particles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Phaser.Particles = {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Phaser.Particles.Arcade = {}

0 commit comments

Comments
 (0)