Skip to content

Commit b868c2c

Browse files
committed
Started revamp of the Tilemap system. Also removed old 'Advanced Physics' and dropped in p2.js which is what I hope we'll eventually use.
1 parent a7230aa commit b868c2c

72 files changed

Lines changed: 6709 additions & 6459 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Version 1.0.7 (in progress in the dev branch)
113113
* World.randomX/Y now works with negative World.bounds values.
114114
* Added killOnComplete parameter to Animation.play. Really useful in situations where you want a Sprite to animate once then kill itself on complete, like an explosion effect.
115115
* Added Sprite.loadTexture(key, frame) which allows you to load a new texture set into an existing sprite rather than having to create a new sprite.
116+
* Tweens .to will now always return the parent (thanks powerfear)
116117

117118

118119
* TODO: look at Sprite.crop (http://www.html5gamedevs.com/topic/1617-error-in-spritecrop/)

build/phaser.js

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Phaser - http://www.phaser.io
1111
*
12-
* v1.0.7 - Built at: Wed, 09 Oct 2013 17:16:16 +0100
12+
* v1.0.7 - Built at: Thu, 10 Oct 2013 16:51:46 +0100
1313
*
1414
* By Richard Davey http://www.photonstorm.com @photonstorm
1515
*
@@ -7340,10 +7340,21 @@ Phaser.Camera.prototype = {
73407340
break;
73417341
}
73427342

7343+
},
7344+
7345+
/**
7346+
* Move the camera focus on a display object instantly.
7347+
* @method Phaser.Camera#focusOn
7348+
* @param {any} displayObject - The display object to focus the camera on. Must have visible x/y properties.
7349+
*/
7350+
focusOn: function (displayObject) {
7351+
7352+
this.setPosition(Math.round(displayObject.x - this.view.halfWidth), Math.round(displayObject.y - this.view.halfHeight));
7353+
73437354
},
73447355

73457356
/**
7346-
* Move the camera focus to a location instantly.
7357+
* Move the camera focus on a location instantly.
73477358
* @method Phaser.Camera#focusOnXY
73487359
* @param {number} x - X position.
73497360
* @param {number} y - Y position.
@@ -16007,6 +16018,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
1600716018
this.prevY = this.y;
1600816019

1600916020
this.updateCache();
16021+
this.updateAnimation();
1601016022

1601116023
// Re-run the camera visibility check
1601216024
if (this._cache.dirty)
@@ -16065,7 +16077,10 @@ Phaser.Sprite.prototype.updateCache = function() {
1606516077
this._cache.dirty = true;
1606616078
}
1606716079

16068-
// Frame updated?
16080+
}
16081+
16082+
Phaser.Sprite.prototype.updateAnimation = function() {
16083+
1606916084
if (this.currentFrame && this.currentFrame.uuid != this._cache.frameID)
1607016085
{
1607116086
this._cache.frameWidth = this.texture.frame.width;
@@ -16119,6 +16134,47 @@ Phaser.Sprite.prototype.postUpdate = function() {
1611916134

1612016135
}
1612116136

16137+
Phaser.Sprite.prototype.loadTexture = function (key, frame) {
16138+
16139+
this.key = key;
16140+
16141+
if (key instanceof Phaser.RenderTexture)
16142+
{
16143+
this.currentFrame = this.game.cache.getTextureFrame(key.name);
16144+
}
16145+
else
16146+
{
16147+
if (key == null || this.game.cache.checkImageKey(key) == false)
16148+
{
16149+
key = '__default';
16150+
}
16151+
16152+
if (this.game.cache.isSpriteSheet(key))
16153+
{
16154+
this.animations.loadFrameData(this.game.cache.getFrameData(key));
16155+
16156+
if (frame !== null)
16157+
{
16158+
if (typeof frame === 'string')
16159+
{
16160+
this.frameName = frame;
16161+
}
16162+
else
16163+
{
16164+
this.frame = frame;
16165+
}
16166+
}
16167+
}
16168+
else
16169+
{
16170+
this.currentFrame = this.game.cache.getFrame(key);
16171+
}
16172+
}
16173+
16174+
this.updateAnimation();
16175+
16176+
}
16177+
1612216178
Phaser.Sprite.prototype.deltaAbsX = function () {
1612316179
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
1612416180
}
@@ -16430,6 +16486,18 @@ Object.defineProperty(Phaser.Sprite.prototype, "inCamera", {
1643016486

1643116487
});
1643216488

16489+
/**
16490+
*
16491+
* @returns {boolean}
16492+
*/
16493+
Object.defineProperty(Phaser.Sprite.prototype, "worldX", {
16494+
16495+
get: function () {
16496+
return 1;
16497+
}
16498+
16499+
});
16500+
1643316501
/**
1643416502
* Get the input enabled state of this Sprite.
1643516503
* @returns {Description}
@@ -22959,6 +23027,7 @@ Phaser.Tween.prototype = {
2295923027
*/
2296023028
pause: function () {
2296123029
this._paused = true;
23030+
this._pausedTime = this.game.time.now;
2296223031
},
2296323032

2296423033
/**
@@ -22968,7 +23037,7 @@ Phaser.Tween.prototype = {
2296823037
*/
2296923038
resume: function () {
2297023039
this._paused = false;
22971-
this._startTime += this.game.time.pauseDuration;
23040+
this._startTime += (this.game.time.now - this._pausedTime);
2297223041
},
2297323042

2297423043
/**
@@ -29081,6 +29150,7 @@ Phaser.Utils.Debug.prototype = {
2908129150
this.line('angle: ' + sprite.angle.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
2908229151
this.line('visible: ' + sprite.visible + ' in camera: ' + sprite.inCamera);
2908329152
this.line('body x: ' + sprite.body.x.toFixed(1) + ' y: ' + sprite.body.y.toFixed(1));
29153+
this.stop();
2908429154

2908529155
// 0 = scaleX
2908629156
// 1 = skewY
@@ -29131,6 +29201,7 @@ Phaser.Utils.Debug.prototype = {
2913129201
this.line('scaleY: ' + sprite.worldTransform[4]);
2913229202
this.line('transX: ' + sprite.worldTransform[2]);
2913329203
this.line('transY: ' + sprite.worldTransform[5]);
29204+
this.stop();
2913429205

2913529206
},
2913629207

@@ -29160,6 +29231,49 @@ Phaser.Utils.Debug.prototype = {
2916029231
this.line('scaleY: ' + sprite.localTransform[4]);
2916129232
this.line('transX: ' + sprite.localTransform[2]);
2916229233
this.line('transY: ' + sprite.localTransform[5]);
29234+
this.stop();
29235+
29236+
},
29237+
29238+
renderSpriteCoords: function (sprite, x, y, color) {
29239+
29240+
if (this.context == null)
29241+
{
29242+
return;
29243+
}
29244+
29245+
color = color || 'rgb(255, 255, 255)';
29246+
29247+
this.start(x, y, color);
29248+
29249+
this.line(sprite.name);
29250+
this.line('x: ' + sprite.x);
29251+
this.line('y: ' + sprite.y);
29252+
this.line('local x: ' + sprite.localTransform[2]);
29253+
this.line('local y: ' + sprite.localTransform[5]);
29254+
this.line('world x: ' + sprite.worldTransform[2]);
29255+
this.line('world y: ' + sprite.worldTransform[5]);
29256+
29257+
this.stop();
29258+
29259+
},
29260+
29261+
renderGroupInfo: function (group, x, y, color) {
29262+
29263+
if (this.context == null)
29264+
{
29265+
return;
29266+
}
29267+
29268+
color = color || 'rgb(255, 255, 255)';
29269+
29270+
this.start(x, y, color);
29271+
29272+
this.line('Group (size: ' + group.length + ')');
29273+
this.line('x: ' + group.x);
29274+
this.line('y: ' + group.y);
29275+
29276+
this.stop();
2916329277

2916429278
},
2916529279

examples/collision/transform.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ function preload() {
1313

1414
game.load.image('atari', 'assets/sprites/atari130xe.png');
1515
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
16+
game.load.image('flectrum', 'assets/sprites/flectrum.png');
1617

1718
}
1819

1920
var testGroup;
2021
var sprite1;
2122
var sprite2;
23+
var sprite3;
2224

2325
function create() {
2426

@@ -61,6 +63,9 @@ function test2 () {
6163
sprite2 = game.add.sprite(-100, 150, 'mushroom');
6264
sprite2.name = 'mushroom';
6365

66+
sprite3 = game.add.sprite(-200, 150, 'flectrum');
67+
sprite3.name = 'tall';
68+
6469
testGroup.x = -600;
6570
testGroup.y = 200;
6671

@@ -88,6 +93,8 @@ function update () {
8893

8994
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
9095

96+
// sprite3.angle += 0.5;
97+
9198
}
9299

93100
function collisionHandler (obj1, obj2) {
@@ -110,6 +117,7 @@ function render() {
110117

111118
game.debug.renderSpriteBody(sprite1);
112119
game.debug.renderSpriteBody(sprite2);
120+
game.debug.renderSpriteBody(sprite3);
113121

114122
game.debug.renderGroupInfo(testGroup, 500, 500);
115123
game.debug.renderPixel(testGroup.x, testGroup.y, 'rgb(255,255,0)');

examples/js.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@
114114
<script src="../src/particles/arcade/ArcadeParticles.js"></script>
115115
<script src="../src/particles/arcade/Emitter.js"></script>
116116

117+
<script src="../src/tilemap/Tile.js"></script>
117118
<script src="../src/tilemap/Tilemap.js"></script>
118119
<script src="../src/tilemap/TilemapLayer.js"></script>
119-
<script src="../src/tilemap/Tile.js"></script>
120-
<script src="../src/tilemap/TilemapRenderer.js"></script>
120+
<script src="../src/tilemap/TilemapParser.js"></script>
121+
<script src="../src/tilemap/Tileset.js"></script>
121122

122123
<script src="../src/PixiPatch.js"></script>

examples/tilemaps/wip1.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
$title = "Tilemap Layer WIP #1";
3+
require('../head.php');
4+
?>
5+
6+
<script type="text/javascript">
7+
8+
// var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
9+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
10+
11+
function preload() {
12+
13+
// game.load.image('snes', 'assets/maps/smb_tiles.png');
14+
// game.load.tilemap('nes', 'assets/maps/mario1.png', 'assets/maps/mario1.json', null, Phaser.Tilemap.JSON);
15+
// game.load.tilemap('snes', 'assets/maps/smb_tiles.png', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.JSON);
16+
17+
// Just loads the level data and specifies the format
18+
// game.load.tilemap('marioLevel1', 'assets/maps/smb_level1.json', Phaser.Tilemap.JSON);
19+
20+
// What about passing in a JSON object though? Need that too. But a CSV would look like a 'string', not an object - how to tell apart from URL?
21+
// game.load.tilemap('marioLevel1', SMB_LEVEL_JSON, Phaser.Tilemap.JSON);
22+
23+
// Exactly the same as loading a sprite sheet :)
24+
game.load.tileset('marioLevel1', 'assets/maps/smb_tiles.png', 32, 32);
25+
26+
}
27+
28+
var layer;
29+
30+
function create() {
31+
32+
game.stage.backgroundColor = '#3d3d3d';
33+
34+
35+
36+
layer = new Phaser.TilemapLayer(game, 0, 0, 500, 500, [], 'snes');
37+
38+
// layer = new Phaser.TilemapLayer(game, 0, 0, 500, 500);
39+
40+
41+
// layer.load(mapData, tileset);
42+
// layer.create(mapWidth, mapHeight, [tileset]);
43+
// layer.updateTileset(key); // can change on the fly
44+
45+
layer.context.fillStyle = 'rgb(255,0,0)';
46+
layer.context.fillRect(0, 0, 200, 300);
47+
game.world._container.addChild(layer.sprite);
48+
49+
layer.create(10, 10);
50+
51+
layer.putTile(2, 2, 1);
52+
layer.putTile(3, 2, 1);
53+
layer.putTile(4, 2, 1);
54+
layer.putTile(5, 2, 1);
55+
layer.putTile(4, 6, 1);
56+
57+
layer.dump();
58+
}
59+
60+
function update() {
61+
62+
63+
}
64+
65+
function render() {
66+
67+
68+
}
69+
70+
</script>
71+
72+
<?php
73+
require('../foot.php');
74+
?>

examples/tweens/chained tweens.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66
<script type="text/javascript">
77

8-
9-
108
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
119

12-
var p;
10+
var p, tween, button, flag = false;
1311

1412
function preload() {
1513

1614
game.load.image('diamond', 'assets/sprites/diamond.png');
15+
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
1716

1817
}
1918

@@ -23,13 +22,30 @@ function create() {
2322

2423
p = game.add.sprite(100, 100, 'diamond');
2524

26-
game.add.tween(p).to({ x: 600 }, 2000, Phaser.Easing.Linear.None, true)
25+
tween = game.add.tween(p).to({ x: 600 }, 2000, Phaser.Easing.Linear.None)
2726
.to({ y: 300 }, 1000, Phaser.Easing.Linear.None)
2827
.to({ x: 100 }, 2000, Phaser.Easing.Linear.None)
2928
.to({ y: 100 }, 1000, Phaser.Easing.Linear.None)
30-
.loop();
29+
.loop()
30+
.start();
31+
32+
button = game.add.button(game.world.centerX, 400, 'button', actionOnClick, this, 2, 1, 0);
3133
}
3234

35+
function actionOnClick() {
36+
37+
if (flag) {
38+
console.log('started');
39+
tween.start();
40+
}
41+
else {
42+
console.log('stopped');
43+
tween.stop();
44+
}
45+
46+
flag = !flag;
47+
48+
}
3349

3450
</script>
3551

0 commit comments

Comments
 (0)