diff --git a/examples/assets/tilemaps/maps/phaser_tiles.json b/examples/assets/tilemaps/maps/phaser_tiles.json new file mode 100644 index 00000000..523e0c8e --- /dev/null +++ b/examples/assets/tilemaps/maps/phaser_tiles.json @@ -0,0 +1,39 @@ +{ "height":6, + "layers":[ + { + "data":[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], + "height":6, + "name":"Ground", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":6, + "x":0, + "y":0 + }], + "orientation":"orthogonal", + "properties": + { + + }, + "tileheight":100, + "tilesets":[ + { + "firstgid":1, + "image":"C:\/Program Files (x86)\/Tiled\/examples\/tmw_desert_spacing.png", + "imageheight":607, + "imagewidth":607, + "margin":1, + "name":"Desert", + "properties": + { + + }, + "spacing":1, + "tileheight":100, + "tilewidth":100 + }], + "tilewidth":100, + "version":1, + "width":6 +} \ No newline at end of file diff --git a/examples/assets/tilemaps/tiles/phaser_tiles.png b/examples/assets/tilemaps/tiles/phaser_tiles.png new file mode 100644 index 00000000..88540c02 Binary files /dev/null and b/examples/assets/tilemaps/tiles/phaser_tiles.png differ diff --git a/examples/games/matching pairs.js b/examples/games/matching pairs.js index 2d35abd6..eea39a97 100644 --- a/examples/games/matching pairs.js +++ b/examples/games/matching pairs.js @@ -1,13 +1,12 @@ // mods by Patrick OReilly -// Twitter: @pato_reilly Web: http://patricko.byethost9.com +// twitter: @pato_reilly var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { - game.load.tilemap('matching', 'assets/maps/phaser_tiles.json', null, Phaser.Tilemap.TILED_JSON); - game.load.image('tiles', 'assets/tiles/phaser_tiles.png'); - + game.load.tilemap('matching', 'assets/tilemaps/maps/phaser_tiles.json', null, Phaser.Tilemap.TILED_JSON); + game.load.tileset('tiles', 'assets/tilemaps/tiles/phaser_tiles.png', 100, 100, -1, 1, 1); } var timeCheck = 0; @@ -37,36 +36,39 @@ var tileBack = 25; var timesUp = '+'; var youWin = '+'; + function create() { - map = game.add.tilemap('matching'); + map = game.add.tilemap('matching'); - // tileset = game.add.tileset('tiles'); + tileset = game.add.tileset('tiles'); + + layer = game.add.tilemapLayer(0, 0, 600, 600, tileset, map, 0); - // layer = game.add.tilemapLayer(0, 0, 600, 600, tileset, map, 0); - - marker = game.add.graphics(); - marker.lineStyle(2, 0x00FF00, 1); - marker.drawRect(0, 0, 100, 100); + //layer.resizeWorld(); + marker = game.add.graphics(); + marker.lineStyle(2, 0x00FF00, 1); + marker.drawRect(0, 0, 100, 100); + randomizeTiles(); } function update() { - + countDownTimer(); - + if (layer.getTileX(game.input.activePointer.worldX) <= 5) // to prevent the marker from going out of bounds { marker.x = layer.getTileX(game.input.activePointer.worldX) * 100; marker.y = layer.getTileY(game.input.activePointer.worldY) * 100; } - if (flipFlag == true) + if (flipFlag == true) { - if (game.time.now - timeCheck > 1000) - { + if (game.time.now - timeCheck >1000) + { flipBack(); } } @@ -74,97 +76,93 @@ function update() { { processClick(); } - } - + + function countDownTimer() { - + var timeLimit = 120; - + myTime = game.time.now; - mySeconds = parseInt(myTime / 1000); + mySeconds = parseInt(myTime/1000); myCountdownSeconds = timeLimit - mySeconds; - - if (myCountdownSeconds <= 0) - { + + if (myCountdownSeconds <= 0) + { // time is up - timesUp = 'Time is up!'; + timesUp = 'Time is up!'; } - } function processClick() { - + currentTile = map.getTile(layer.getTileX(marker.x), layer.getTileY(marker.y)); - currentTilePosition = ((layer.getTileY(game.input.activePointer.worldY) + 1) * 6) - (6 - (layer.getTileX(game.input.activePointer.worldX) + 1)); - + currentTilePosition = ((layer.getTileY(game.input.activePointer.worldY)+1)*6)-(6-(layer.getTileX(game.input.activePointer.worldX)+1)); + if (game.input.mousePointer.isDown) - { + { // check to make sure the tile is not already flipped - if (currentTile == tileBack) + if (currentTile == tileBack) { // get the corresponding item out of squareList - currentNum = squareList[currentTilePosition - 1]; + currentNum = squareList[currentTilePosition-1]; flipOver(); - squareCounter++; - + squareCounter++; // is the second tile of pair flipped? - if (squareCounter == 2) + if (squareCounter == 2) { // reset squareCounter squareCounter = 0; square2Num = currentNum; - // check for match if (square1Num == square2Num) { - masterCounter++; - - if (masterCounter == 18) + masterCounter++; + + if (masterCounter == 18) { // go "win" youWin = 'Got them all!'; - } + } } else { savedSquareX2 = layer.getTileX(marker.x); savedSquareY2 = layer.getTileY(marker.y); - flipFlag = true; - timeCheck = game.time.now; - } - } + flipFlag = true; + timeCheck = game.time.now; + } + } else { savedSquareX1 = layer.getTileX(marker.x); savedSquareY1 = layer.getTileY(marker.y); - square1Num = currentNum; - } - } - } + square1Num = currentNum; + } + } + } } - + function flipOver() { - + map.putTile(currentNum, layer.getTileX(marker.x), layer.getTileY(marker.y)); } - + function flipBack() { - + flipFlag = false; - + map.putTile(tileBack, savedSquareX1, savedSquareY1); map.putTile(tileBack, savedSquareX2, savedSquareY2); - + } - + function randomizeTiles() { for (num = 1; num <= 18; num++) { startList.push(num); } - for (num = 1; num <= 18; num++) { startList.push(num); @@ -172,24 +170,24 @@ function randomizeTiles() { // for debugging myString1 = startList.toString(); - + // randomize squareList - for (i = 1; i <= 36; i++) + for (i = 1; i <=36; i++) { - randomPosition = game.rnd.integerInRange(0, startList.length); - - thisNumber = startList[randomPosition]; - + randomPosition = game.rnd.integerInRange(0,startList.length); + + thisNumber = startList[ randomPosition ]; + squareList.push(thisNumber); - + a = startList.indexOf(thisNumber); - - startList.splice(a, 1); + + startList.splice( a, 1); } - + // for debugging myString2 = squareList.toString(); - + for (col = 0; col < 6; col++) { for (row = 0; row < 6; row++) @@ -200,8 +198,8 @@ function randomizeTiles() { } function getHiddenTile() { - - thisTile = squareList[currentTilePosition - 1]; + + thisTile = squareList[currentTilePosition-1]; return thisTile; } @@ -211,7 +209,13 @@ function render() { game.debug.renderText(youWin, 620, 240, 'rgb(0,255,0)'); game.debug.renderText('Time: ' + myCountdownSeconds, 620, 15, 'rgb(0,255,0)'); + + //game.debug.renderText('squareCounter: ' + squareCounter, 620, 272, 'rgb(0,0,255)'); game.debug.renderText('Matched Pairs: ' + masterCounter, 620, 304, 'rgb(0,0,255)'); + + //game.debug.renderText('startList: ' + myString1, 620, 208, 'rgb(255,0,0)'); + //game.debug.renderText('squareList: ' + myString2, 620, 240, 'rgb(255,0,0)'); + game.debug.renderText('Tile: ' + map.getTile(layer.getTileX(marker.x), layer.getTileY(marker.y)), 620, 48, 'rgb(255,0,0)'); game.debug.renderText('LayerX: ' + layer.getTileX(marker.x), 620, 80, 'rgb(255,0,0)'); @@ -219,5 +223,4 @@ function render() { game.debug.renderText('Tile Position: ' + currentTilePosition, 620, 144, 'rgb(255,0,0)'); game.debug.renderText('Hidden Tile: ' + getHiddenTile(), 620, 176, 'rgb(255,0,0)'); - -} +} \ No newline at end of file diff --git a/examples/wip/astro balls.js b/examples/wip/astro balls.js index ce9069de..d1b1901b 100644 --- a/examples/wip/astro balls.js +++ b/examples/wip/astro balls.js @@ -1,5 +1,5 @@ -var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); +var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { diff --git a/examples/wip/fixed to cam.js b/examples/wip/fixed to cam.js index eb62ea43..08920976 100644 --- a/examples/wip/fixed to cam.js +++ b/examples/wip/fixed to cam.js @@ -41,6 +41,13 @@ function create() { var text2 = game.add.bitmapText(200, 500, 'desyrel', 'camera fixies', 32); text2.fixedToCamera = true; + // Test fixing a Graphics object to the Camera + var graphics = game.add.graphics(0, 0); + graphics.fixedToCamera = true; + graphics.beginFill(0xFF3300); + graphics.lineStyle(2, 0x0000FF, 1); + graphics.drawRect(50, 250, 100, 100); + // Button! do mouse events still work then? game.camera.follow(mushroom); diff --git a/examples/wip/index2.php b/examples/wip/index2.php new file mode 100644 index 00000000..a7a73672 --- /dev/null +++ b/examples/wip/index2.php @@ -0,0 +1,119 @@ + $value) + { + if (is_array($value) && count($value) > 0) + { + $total += count($value); + } + } + + function getFile() { + + global $files, $dir, $filename, $title, $code; + + if (isset($_GET['d']) && isset($_GET['f'])) + { + $dir = urldecode($_GET['d']); + $filename = urldecode($_GET['d']) . '/' . urldecode($_GET['f']); + $title = urldecode($_GET['t']); + + if (file_exists($filename)) + { + $code = file_get_contents($filename); + $files = dirToArray($dir); + } + } + + } + + function dirToArray($dir) { + + $ignore = array('.', '..', '_site', 'assets', 'gfx', 'states', 'book', 'filters', 'misc'); + $result = array(); + $root = scandir($dir); + $dirs = array_diff($root, $ignore); + + foreach ($dirs as $key => $value) + { + if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) + { + $result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value); + } + else + { + if (substr($value, -3) == '.js') + { + $result[] = $value; + } + } + } + + return $result; + } + + function printJSLinks($dir, $files) { + + $output = ""; + + foreach ($files as $key => $value) + { + $value2 = substr($value, 0, -3); + $file = urlencode($value); + + $output .= "$value2
"; + } + + return $output; + + } +?> + + + + + + phaser + + + + + + + + + + +
+ + + + +
+ +

work in progress examples

+ + + +
+ + + \ No newline at end of file diff --git a/examples/wip/keyboard.js b/examples/wip/keyboard.js new file mode 100644 index 00000000..a287dc2a --- /dev/null +++ b/examples/wip/keyboard.js @@ -0,0 +1,57 @@ + +// var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); +var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('ship', 'assets/sprites/thrust_ship2.png'); + +} + +var ship; +var cursors; + +function create() { + + game.stage.backgroundColor = '#2d2d2d'; + + ship = game.add.sprite(200, 200, 'ship'); + ship.physicsEnabled = true; + // We do this because our ship is shaped like a triangle, not a square :) + ship.body.addPolygon({}, 29, 23 , 0, 23 , 14, 1); + + cursors = game.input.keyboard.createCursorKeys(); + +} + +function update() { + + if (cursors.left.isDown) + { + ship.body.rotateLeft(100); + } + else if (cursors.right.isDown) + { + ship.body.rotateRight(100); + } + else + { + ship.body.setZeroRotation(); + } + + if (cursors.up.isDown) + { + ship.body.thrust(400); + } + else if (cursors.down.isDown) + { + ship.body.reverse(400); + } + +} + +function render() { + + game.debug.renderPhysicsBody(ship.body); + +} diff --git a/examples/wip/state parameters.js b/examples/wip/state parameters.js index c88ba121..2f2e402e 100644 --- a/examples/wip/state parameters.js +++ b/examples/wip/state parameters.js @@ -21,6 +21,7 @@ BasicGame.Boot.prototype = { create: function () { + console.log('Boot create'); this.game.state.start('Preloader', true, false, this.a, this.b); } @@ -48,6 +49,7 @@ BasicGame.Preloader.prototype = { create: function () { + console.log('Preloader create'); this.game.state.start('MainMenu', true, false, this.a, this.b); } @@ -89,4 +91,4 @@ game.state.add('Boot', BasicGame.Boot); game.state.add('Preloader', BasicGame.Preloader); game.state.add('MainMenu', BasicGame.MainMenu); -game.state.start('Boot'); +game.state.start('Boot', true, false, 'hello', 'world'); diff --git a/examples/wip/tilemap1.js b/examples/wip/tilemap1.js index a1b2737e..fccd7f2c 100644 --- a/examples/wip/tilemap1.js +++ b/examples/wip/tilemap1.js @@ -1,6 +1,6 @@ -var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); -// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); +// var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { @@ -36,7 +36,7 @@ function create() { layer = map.createLayer('Tile Layer 1'); - layer.resizeWorld(); + // layer.resizeWorld(); map.setCollisionBetween(1, 12); diff --git a/src/core/StateManager.js b/src/core/StateManager.js index 081e5dcd..ac25f136 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -141,13 +141,12 @@ Phaser.StateManager.prototype = { if (typeof this._pendingState === 'string') { // State was already added, so just start it - this.start(this._pendingState, false, false); + // this.start(this._pendingState, false, false); } else { this.add('default', this._pendingState, true); } - } }, @@ -251,12 +250,6 @@ Phaser.StateManager.prototype = { { this._args = Array.prototype.splice.call(arguments, 3); } - - // Already got a state running? - if (this.current) - { - this.onShutDownCallback.call(this.callbackContext, this.game); - } } }, @@ -307,7 +300,6 @@ Phaser.StateManager.prototype = { if (this.game.load.totalQueuedFiles() === 0) { this.loadComplete(); - // this.game.loadComplete(); } else { @@ -319,10 +311,12 @@ Phaser.StateManager.prototype = { { // No init? Then there was nothing to load either this.loadComplete(); - // this.game.loadComplete(); } - this._pendingState = null; + if (this.current === this._pendingState) + { + this._pendingState = null; + } } }, diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index 0f53eedb..85c61bb2 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -669,7 +669,8 @@ Phaser.TilemapLayer.prototype.render = function () { // Only needed if running in WebGL, otherwise this array will never get cleared down I don't think! if (this.game.renderType === Phaser.WEBGL) { - PIXI.texturesToUpdate.push(this.baseTexture); + // PIXI.updateWebGLTexture(this.baseTexture, renderSession.gl); + PIXI.updateWebGLTexture(this.baseTexture, this.game.renderer.gl); } this.dirty = false;