Skip to content

Commit 79dc356

Browse files
committed
Fixed some issues in Tilemap collision, updated the Emitter so x/y controls the point of emission (to stop collision getting out of whack) and fixed the postUpdate in body.
1 parent 336de31 commit 79dc356

10 files changed

Lines changed: 617 additions & 83 deletions

File tree

build/phaser-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/phaser.js

Lines changed: 302 additions & 56 deletions
Large diffs are not rendered by default.

examples/mapcollide.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
(function () {
1414

15-
// var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
1615
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
1716

1817
function preload() {
@@ -34,20 +33,15 @@ function create() {
3433
// floor
3534
map.setCollisionRange(80, 97, true, true, true, true);
3635

37-
// pipes
38-
// map.setCollisionRange(31, 32, true, true, true, true);
39-
// map.setCollisionRange(37, 38, true, true, true, true);
40-
// map.setCollisionRange(39, 40, true, true, true, true);
41-
// map.setCollisionRange(45, 46, true, true, true, true);
42-
// map.setCollisionRange(73, 74, true, true, true, true);
43-
4436
// one-ways
4537
map.setCollisionRange(15, 17, true, true, false, true);
4638

47-
p = game.add.sprite(0, 0, 'player');
48-
// p.body.velocity.y = 150;
49-
// p.body.gravity.y = 10;
50-
// p.body.bounce.y = 0.5;
39+
p = game.add.sprite(32, 32, 'player');
40+
41+
p.body.bounce.y = 0.4;
42+
p.body.collideWorldBounds = true;
43+
44+
game.camera.follow(p);
5145

5246
}
5347

@@ -56,12 +50,11 @@ function update() {
5650
map.collide(p);
5751

5852
p.body.velocity.x = 0;
59-
p.body.acceleration.y = 250;
53+
p.body.acceleration.y = 500;
6054

6155
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
6256
{
6357
p.body.velocity.x = -150;
64-
// game.camera.x -= 8;
6558
}
6659
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
6760
{

examples/mariocombo/particles.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - mario party(cles)</title>
5+
<script src="phaser-min.js"></script>
6+
<style type="text/css">
7+
body {
8+
margin: 0;
9+
font-family: sans-serif;
10+
}
11+
12+
p {
13+
padding: 16px;
14+
margin: 0px;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
20+
<div id="game"></div>
21+
22+
<script type="text/javascript">
23+
24+
(function () {
25+
26+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });
27+
28+
function preload() {
29+
30+
game.load.tilemap('background', 'assets/smb_bg.png', 'assets/smb_bg.json', null, Phaser.Tilemap.JSON);
31+
game.load.tilemap('level1', 'assets/smb_tiles.png', 'assets/smb_level1.json', null, Phaser.Tilemap.JSON);
32+
game.load.spritesheet('balls', 'assets/balls.png', 17, 17);
33+
game.load.image('phaser', 'assets/phaser.png');
34+
35+
}
36+
37+
var p;
38+
var map;
39+
40+
function create() {
41+
42+
game.stage.backgroundColor = '#787878';
43+
44+
game.add.tilemap(0, 0, 'background');
45+
46+
map = game.add.tilemap(0, 0, 'level1');
47+
map.setCollisionByIndex([9,10,11,14,15,16,18,19,22,23,24,32,37,38], true, true, true, true);
48+
49+
p = game.add.emitter(300, 50, 500);
50+
p.bounce = 0.5;
51+
p.makeParticles('balls', [0,1,2,3,4,5], 500, 1);
52+
p.minParticleSpeed.setTo(-150, 150);
53+
p.maxParticleSpeed.setTo(100, 100);
54+
p.gravity = 8;
55+
p.start(false, 5000, 50);
56+
57+
var logo = game.add.sprite(688, 8, 'phaser');
58+
logo.scrollFactor.setTo(0, 0);
59+
60+
game.add.tween(p).to({ x: 4000 }, 7500, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
61+
62+
game.input.onDown.add(goFull, this);
63+
64+
}
65+
66+
function goFull() {
67+
game.stage.scale.startFullScreen();
68+
}
69+
70+
function update() {
71+
72+
map.collide(p);
73+
74+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
75+
{
76+
game.camera.x -= 8;
77+
}
78+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
79+
{
80+
game.camera.x += 8;
81+
}
82+
83+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
84+
{
85+
game.camera.y -= 8;
86+
}
87+
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
88+
{
89+
game.camera.y += 8;
90+
}
91+
92+
}
93+
94+
})();
95+
</script>
96+
97+
<p>Left / Right arrows to scroll the map</p>
98+
<p>Click game to full-screen (if supported)</p>
99+
<p>Highlights a few visual glitches I need to work on :)</p>
100+
<p>Created with <a href="https://github.com/photonstorm/phaser">Phaser 1.0</a> by <a href="https://twitter.com/photonstorm">@photonstorm</a></p>
101+
102+
</body>
103+
</html>

examples/statetest.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
19+
game.load.tilemap('mario', 'assets/maps/mario1.png', 'assets/maps/mario1.json', null, Phaser.Tilemap.JSON);
20+
game.load.image('player', 'assets/sprites/phaser-dude.png');
21+
22+
}
23+
24+
var map;
25+
var p;
26+
27+
function create() {
28+
29+
game.stage.backgroundColor = '#787878';
30+
31+
map = game.add.tilemap(0, 0, 'mario');
32+
33+
// floor
34+
map.setCollisionRange(80, 97, true, true, true, true);
35+
36+
// one-ways
37+
map.setCollisionRange(15, 17, true, true, false, true);
38+
39+
p = game.add.sprite(32, 32, 'player');
40+
41+
p.body.bounce.y = 0.4;
42+
p.body.collideWorldBounds = true;
43+
44+
game.camera.follow(p);
45+
46+
}
47+
48+
function update() {
49+
50+
map.collide(p);
51+
52+
p.body.velocity.x = 0;
53+
p.body.acceleration.y = 500;
54+
55+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
56+
{
57+
p.body.velocity.x = -150;
58+
}
59+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
60+
{
61+
p.body.velocity.x = 150;
62+
}
63+
64+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
65+
{
66+
if (p.body.touching.down)
67+
{
68+
p.body.velocity.y = -200;
69+
}
70+
}
71+
72+
}
73+
74+
function render() {
75+
76+
game.debug.renderSpriteCorners(p);
77+
game.debug.renderSpriteCollision(p, 32, 320);
78+
79+
}
80+
81+
})();
82+
</script>
83+
84+
</body>
85+
</html>

examples/supermario2.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
function preload() {
18+
19+
game.load.tilemap('background', 'assets/maps/smb_bg.png', 'assets/maps/smb_bg.json', null, Phaser.Tilemap.JSON);
20+
game.load.tilemap('level1', 'assets/maps/smb_tiles.png', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.JSON);
21+
game.load.spritesheet('balls', 'assets/sprites/balls.png', 17, 17);
22+
23+
}
24+
25+
var p;
26+
var map;
27+
var test = [];
28+
var g;
29+
30+
function create() {
31+
32+
game.stage.backgroundColor = '#787878';
33+
34+
game.add.tilemap(0, 0, 'background');
35+
36+
map = game.add.tilemap(0, 0, 'level1');
37+
map.setCollisionByIndex([9,10,11,14,15,16,18,19,22,23,24,32,37,38], true, true, true, true);
38+
39+
p = game.add.emitter(300, 50, 500);
40+
p.bounce = 0.5;
41+
p.makeParticles('balls', [0,1,2,3,4,5], 500, 1);
42+
p.minParticleSpeed.setTo(-150, 150);
43+
p.maxParticleSpeed.setTo(100, 100);
44+
p.gravity = 8;
45+
p.start(false, 5000, 50);
46+
47+
game.add.tween(p).to({ x: 4000 }, 7500, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
48+
49+
}
50+
51+
function update() {
52+
53+
map.collide(g);
54+
map.collide(p);
55+
56+
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
57+
{
58+
game.camera.x -= 8;
59+
}
60+
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
61+
{
62+
game.camera.x += 8;
63+
}
64+
65+
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
66+
{
67+
game.camera.y -= 8;
68+
}
69+
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
70+
{
71+
game.camera.y += 8;
72+
}
73+
74+
}
75+
76+
function render() {
77+
}
78+
79+
})();
80+
</script>
81+
82+
</body>
83+
</html>

src/particles/arcade/Emitter.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
1717
/**
1818
* The X position of the top left corner of the emitter in world space.
1919
*/
20-
this.x = x;
20+
this.x = 0;
2121

2222
/**
2323
* The Y position of the top left corner of emitter in world space.
2424
*/
25-
this.y = y;
25+
this.y = 0;
2626

2727
/**
2828
* The width of the emitter. Particles can be randomly generated from anywhere within this box.
@@ -141,8 +141,8 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
141141
* Emitter.x and Emitter.y control the containers location, which updates all current particles
142142
* Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
143143
*/
144-
this.emitX = 0;
145-
this.emitY = 0;
144+
this.emitX = x;
145+
this.emitY = y;
146146

147147
};
148148

@@ -241,6 +241,7 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
241241
if (collide > 0)
242242
{
243243
particle.body.allowCollision.any = true;
244+
particle.body.allowCollision.none = false;
244245
}
245246
else
246247
{
@@ -495,6 +496,30 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "visible", {
495496

496497
});
497498

499+
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "x", {
500+
501+
get: function () {
502+
return this.emitX;
503+
},
504+
505+
set: function (value) {
506+
this.emitX = value;
507+
}
508+
509+
});
510+
511+
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "y", {
512+
513+
get: function () {
514+
return this.emitY;
515+
},
516+
517+
set: function (value) {
518+
this.emitY = value;
519+
}
520+
521+
});
522+
498523
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", {
499524

500525
get: function () {

0 commit comments

Comments
 (0)