From f17cdd9c32de44040195eec6ba6f4a221cd1da8f Mon Sep 17 00:00:00 2001 From: alvinsight Date: Fri, 28 Feb 2014 18:22:52 +0000 Subject: [PATCH] Updated a lot of examples to Phaser 2.0 :) --- examples/camera/basic follow.js | 2 -- examples/debug/debug physics.js | 11 ++++----- examples/debug/debug sprite.js | 2 -- examples/display/bitmapdata wobble.js | 6 ++++- examples/display/pixi render texture.js | 6 ++--- examples/display/render texture mirror.js | 6 +++-- examples/groups/group transform - tween.js | 4 ++-- examples/groups/sub groups - group length.js | 6 ++--- examples/input/bring a child to top.js | 2 +- examples/input/drag several sprites.js | 2 +- examples/loader/load bitmap font.js | 2 +- examples/loader/pick images from cache.js | 2 +- examples/sprites/dynamic crop.js | 1 + examples/sprites/horizontal crop.js | 22 ++++++++++-------- examples/sprites/move a sprite.js | 4 +--- examples/sprites/sprite rotation.js | 8 +++---- examples/sprites/vertical crop.js | 23 ++++++++++++------- examples/text/bitmap fonts.js | 6 ++--- examples/text/google webfonts.js | 2 +- .../colliding with tiling sprite.js | 15 ++++++------ examples/time/basic looped event.js | 3 ++- examples/time/basic repeat event.js | 4 +--- examples/time/remove event.js | 4 ++-- examples/wip/google webfont.js | 2 +- 24 files changed, 77 insertions(+), 68 deletions(-) diff --git a/examples/camera/basic follow.js b/examples/camera/basic follow.js index 5a949b48..fd152fee 100644 --- a/examples/camera/basic follow.js +++ b/examples/camera/basic follow.js @@ -69,6 +69,4 @@ function render() { game.debug.renderSpriteCoords(player, 32, 200); game.debug.renderSpriteCoords(fixed, 600, 200); - // game.debug.renderSpriteCoords(game.world._container, 32, 400); - } diff --git a/examples/debug/debug physics.js b/examples/debug/debug physics.js index 01bab7d8..8c9ff077 100644 --- a/examples/debug/debug physics.js +++ b/examples/debug/debug physics.js @@ -20,20 +20,20 @@ function create() { sprite = game.add.sprite(0, 0, 'sprite'); sprite.alpha = 0.5 ; sprite.x = game.width / 2 ; - sprite.anchor.x = sprite.anchor.y = 0.5 ; + sprite.physicsEnabled = true; // create sprite B otherSprite = game.add.sprite(0, 0, 'otherSprite'); otherSprite.alpha = 0.5 ; otherSprite.x = (game.width / 2) + 150 ; otherSprite.y = (game.height / 2) + 150 ; - otherSprite.anchor.x = sprite.anchor.y = 0.5 ; + otherSprite.physicsEnabled = true; otherSprite.body.immovable = true ; } function update() { - game.physics.collide( sprite, otherSprite ) ; + // game.physics.collide( sprite, otherSprite ) ; // Move sprite up and down smoothly for show var tStep = Math.sin( counter ) ; @@ -45,9 +45,8 @@ function update() function render() { // Physics - game.debug.renderSpriteBody(sprite); - game.debug.renderSpriteCollision(sprite, 32, 32); + game.debug.renderSpriteBounds(sprite); - game.debug.renderSpriteBody(otherSprite); + game.debug.renderSpriteBounds(otherSprite); } diff --git a/examples/debug/debug sprite.js b/examples/debug/debug sprite.js index 4ebfe778..2af87e24 100644 --- a/examples/debug/debug sprite.js +++ b/examples/debug/debug sprite.js @@ -35,7 +35,5 @@ function render() { // Sprite debug info game.debug.renderSpriteInfo(sprite, 32, 32); - game.debug.renderLocalTransformInfo(sprite, 32, 160); - game.debug.renderWorldTransformInfo(sprite, 32, 290); } diff --git a/examples/display/bitmapdata wobble.js b/examples/display/bitmapdata wobble.js index 07224ba6..8206e98e 100644 --- a/examples/display/bitmapdata wobble.js +++ b/examples/display/bitmapdata wobble.js @@ -1,5 +1,5 @@ -var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update }); function preload() { @@ -28,6 +28,8 @@ function create() { // Populate the wave with some data waveData = game.math.sinCosGenerator(32, 8, 8, 2); + console.log(bmd.context) + } function update() { @@ -44,6 +46,8 @@ function update() { function updateWobblyBall() { + + var s = 0; var copyRect = { x: 0, y: 0, w: wavePixelChunk, h: 32 }; var copyPoint = { x: 0, y: 0 }; diff --git a/examples/display/pixi render texture.js b/examples/display/pixi render texture.js index 0e92b0f6..7bd12557 100644 --- a/examples/display/pixi render texture.js +++ b/examples/display/pixi render texture.js @@ -39,12 +39,12 @@ function create() { stuffContainer = game.add.group(); stuffContainer.x = 800/2; - stuffContainer.y = 600/2 + stuffContainer.y = 600/2; // now create some items and randomly position them in the stuff container for (var i = 0; i < 20; i++) { - var item = stuffContainer.create(Math.random() * 400 - 200, Math.random() * 400 - 200, game.rnd.pick(game.cache.getImageKeys())); + var item = stuffContainer.create(Math.random() * 400 - 200, Math.random() * 400 - 200, game.rnd.pick(game.cache.getKeys(Phaser.Cache.IMAGE))); item.anchor.setTo(0.5, 0.5); } @@ -73,6 +73,6 @@ function update() { // render the stage to the texture // the true clears the texture before content is rendered - renderTexture2.renderXY(game.stage.display, 0, 0, true); + renderTexture2.renderXY(game.stage, 0, 0, true); } diff --git a/examples/display/render texture mirror.js b/examples/display/render texture mirror.js index b8331c86..56e3696f 100644 --- a/examples/display/render texture mirror.js +++ b/examples/display/render texture mirror.js @@ -27,11 +27,13 @@ function create() { function update() { + + if (!game.input.activePointer.position.isZero()) { // This time we'll draw the ball sprite twice, in a mirror effect - texture.renderXY(ball, game.input.activePointer.x, game.input.activePointer.y, false, true); - texture.renderXY(ball, game.input.activePointer.x, 600 - game.input.activePointer.y, false, true); + texture.renderXY(ball, game.input.activePointer.x, game.input.activePointer.y, true); + texture.renderXY(ball, game.input.activePointer.x, 600 - game.input.activePointer.y, true); } } diff --git a/examples/groups/group transform - tween.js b/examples/groups/group transform - tween.js index 7b37db20..5fbc61bd 100644 --- a/examples/groups/group transform - tween.js +++ b/examples/groups/group transform - tween.js @@ -35,12 +35,12 @@ function create() { eye = robot.create(335, 173,'eye'); // Tween the robot's size, so all the components also scaled. - game.add.tween(robot._container.scale).to( {x: 1.2, y: 1.2}, 1000, Phaser.Easing.Back.InOut, true, 0, false).yoyo(true); + game.add.tween(robot.scale).to( {x: 1.2, y: 1.2}, 1000, Phaser.Easing.Back.InOut, true, 0, false).yoyo(true); } function render() { - game.debug.renderText('The robot is a group and every component is a sprite.', 240, 580); + game.debug.renderText('The robot is a group and every component is a sprite.', 32,32); } diff --git a/examples/groups/sub groups - group length.js b/examples/groups/sub groups - group length.js index 0311b95d..8142aceb 100644 --- a/examples/groups/sub groups - group length.js +++ b/examples/groups/sub groups - group length.js @@ -25,9 +25,9 @@ function create() { normalBaddies = game.add.group(); purpleBaddies = game.add.group(); - // Add both teams to enemies group, using the Pixi container otherwise it's impossible - enemies.add(normalBaddies._container); - enemies.add(purpleBaddies._container); + + enemies.add(normalBaddies); + enemies.add(purpleBaddies); // Create a ufo as a friend sprite. diff --git a/examples/input/bring a child to top.js b/examples/input/bring a child to top.js index de80a920..d3637acf 100644 --- a/examples/input/bring a child to top.js +++ b/examples/input/bring a child to top.js @@ -16,7 +16,7 @@ function preload() { function create() { // This returns an array of all the image keys in the cache - var images = game.cache.getImageKeys(); + var images = game.cache.getKeys(Phaser.Cache.IMAGE); // Now let's create some random sprites and enable them all for drag and 'bring to top' for (var i = 0; i < 20; i++) diff --git a/examples/input/drag several sprites.js b/examples/input/drag several sprites.js index d2fe242f..0d0ad7c0 100644 --- a/examples/input/drag several sprites.js +++ b/examples/input/drag several sprites.js @@ -17,7 +17,7 @@ function preload() { function create() { // This returns an array of all the image keys in the cache - var images = game.cache.getImageKeys(); + var images = game.cache.getKeys(Phaser.Cache.IMAGE); var test = game.add.group(); diff --git a/examples/loader/load bitmap font.js b/examples/loader/load bitmap font.js index 6523470d..e7e2cd74 100644 --- a/examples/loader/load bitmap font.js +++ b/examples/loader/load bitmap font.js @@ -25,7 +25,7 @@ function create() { game.stage.backgroundColor = '#0072bc'; - text = game.add.bitmapText(200, 100, 'Bitmap Fonts!', { font: '64px Desyrel', align: 'center' }); + text = game.add.bitmapText(200, 100, 'desyrel','Bitmap Fonts!',64); } diff --git a/examples/loader/pick images from cache.js b/examples/loader/pick images from cache.js index 071bbf70..ee6f4936 100644 --- a/examples/loader/pick images from cache.js +++ b/examples/loader/pick images from cache.js @@ -17,7 +17,7 @@ function preload() { function create() { // This returns an array of all the image keys in the cache - var images = game.cache.getImageKeys(); + var images = game.cache.getKeys(Phaser.Cache.IMAGE); // Now let's create some random sprites and enable them all for drag and 'bring to top' for (var i = 0; i < 20; i++) diff --git a/examples/sprites/dynamic crop.js b/examples/sprites/dynamic crop.js index 9922d0a0..1fdfa533 100644 --- a/examples/sprites/dynamic crop.js +++ b/examples/sprites/dynamic crop.js @@ -11,6 +11,7 @@ function create() { pic = game.add.sprite(0, 0, 'trsi'); + pic.cropEnabled = true; pic.crop.width = 128; diff --git a/examples/sprites/horizontal crop.js b/examples/sprites/horizontal crop.js index 77f66dc7..e3d2a9f2 100644 --- a/examples/sprites/horizontal crop.js +++ b/examples/sprites/horizontal crop.js @@ -1,23 +1,27 @@ -var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update : update }); function preload() { game.load.image('trsi', 'assets/pics/trsipic1_lazur.jpg'); } +var pic; +var cropRect; + function create() { - var pic = game.add.sprite(game.world.centerX, 550, 'trsi'); + pic = game.add.sprite(game.world.centerX, 550, 'trsi'); pic.anchor.setTo(0.5, 1); - - // By default Sprites ignore the crop setting, you have to explicitly enable it like this: - pic.cropEnabled = true; - // Set the crop rect width to zero - pic.crop.width = 0; + cropRect = {x : 0, y : 0 , width : 0, height : pic.height}; - // Here we'll tween the crop rect, from a width of zero to full width, and back again - game.add.tween(pic.crop).to( { width: pic.width }, 3000, Phaser.Easing.Bounce.Out, true, 0, 1000, true); + // Here we'll tween the crop rect, from a width of zero to full width, and back again + game.add.tween(cropRect).to( { width: pic.width }, 3000, Phaser.Easing.Bounce.Out, true, 0, 1000, true); } + +function update () { + // the crop method takes a rectangle object as a parameter + pic.crop(cropRect); +} diff --git a/examples/sprites/move a sprite.js b/examples/sprites/move a sprite.js index 1d784c94..50235937 100644 --- a/examples/sprites/move a sprite.js +++ b/examples/sprites/move a sprite.js @@ -10,7 +10,7 @@ var s; function create() { s = game.add.sprite(game.world.centerX, game.world.centerY, 'bot'); - // s.anchor.setTo(0.5, 0.5); + s.anchor.setTo(0.5, 0.5); s.scale.setTo(2, 2); s.animations.add('run'); @@ -41,8 +41,6 @@ function update() { } function render() { - - game.debug.renderSpriteCorners(s, false, false); game.debug.renderSpriteInfo(s, 20, 32); } diff --git a/examples/sprites/sprite rotation.js b/examples/sprites/sprite rotation.js index 5ee44391..edc15076 100644 --- a/examples/sprites/sprite rotation.js +++ b/examples/sprites/sprite rotation.js @@ -29,9 +29,9 @@ function update() { function render() { game.debug.renderSpriteInfo(sprite, 32, 32); - game.debug.renderText('angularVelocity: ' + sprite.body.angularVelocity, 32, 200); - game.debug.renderText('angularAcceleration: ' + sprite.body.angularAcceleration, 32, 232); - game.debug.renderText('angularDrag: ' + sprite.body.angularDrag, 32, 264); - game.debug.renderText('deltaZ: ' + sprite.body.deltaZ(), 32, 296); + // game.debug.renderText('angularVelocity: ' + sprite.body.angularVelocity, 32, 200); + // game.debug.renderText('angularAcceleration: ' + sprite.body.angularAcceleration, 32, 232); + // game.debug.renderText('angularDrag: ' + sprite.body.angularDrag, 32, 264); + // game.debug.renderText('deltaZ: ' + sprite.body.deltaZ(), 32, 296); } diff --git a/examples/sprites/vertical crop.js b/examples/sprites/vertical crop.js index 09bd2887..5dd749be 100644 --- a/examples/sprites/vertical crop.js +++ b/examples/sprites/vertical crop.js @@ -1,23 +1,30 @@ -var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create , update : update}); function preload() { game.load.image('trsi', 'assets/pics/trsipic1_lazur.jpg'); } +var pic; +var cropRect; + function create() { - var pic = game.add.sprite(game.world.centerX, 550, 'trsi'); + pic = game.add.sprite(game.world.centerX, 550, 'trsi'); pic.anchor.setTo(0.5, 1); - // By default Sprites ignore the crop setting, you have to explicitly enable it like this: - pic.cropEnabled = true; - - // Set the crop rect height to zero - pic.crop.height = 0; + + cropRect = {x : 0, y : 0 , width : pic.width, height : 0}; // Here we'll tween the crop rect, from a height of zero to full height, and back again - game.add.tween(pic.crop).to( { height: pic.height }, 3000, Phaser.Easing.Bounce.Out, true, 0, 1000, true); + game.add.tween(cropRect).to( { height: pic.height }, 3000, Phaser.Easing.Bounce.Out, true, 0, 1000, true); } + +function update () { + // the crop method takes a rectangle object as a parameter + pic.crop(cropRect); +} + + diff --git a/examples/text/bitmap fonts.js b/examples/text/bitmap fonts.js index 4a819604..5cf0d9c2 100644 --- a/examples/text/bitmap fonts.js +++ b/examples/text/bitmap fonts.js @@ -7,16 +7,16 @@ function preload() { } -var text; +var bpmText; function create() { - text = game.add.bitmapText(200, 100, 'Phaser & Pixi\nrocking!', { font: '64px Desyrel', align: 'center' }); + bmpText = game.add.bitmapText(200, 100, 'desyrel','Phaser & Pixi \nrocking!',64); } function update() { - text.setText('Phaser & Pixi\nrocking!\n' + Math.round(game.time.now)); + bmpText.setText('Phaser & Pixi\nrocking!\n' + Math.round(game.time.now)); } diff --git a/examples/text/google webfonts.js b/examples/text/google webfonts.js index 814f7541..5fc874c7 100644 --- a/examples/text/google webfonts.js +++ b/examples/text/google webfonts.js @@ -19,7 +19,7 @@ WebFontConfig = { function preload() { // Load the Google WebFont Loader script - game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'); + game.load.script('webfont', 'http://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'); } diff --git a/examples/tile sprites/colliding with tiling sprite.js b/examples/tile sprites/colliding with tiling sprite.js index 7f95f935..90206a7d 100644 --- a/examples/tile sprites/colliding with tiling sprite.js +++ b/examples/tile sprites/colliding with tiling sprite.js @@ -15,13 +15,14 @@ function preload() { function create() { ball = game.add.sprite(400, 0, 'ball'); - - ball.body.gravity.y = 200; - ball.body.bounce.y = 1; + ball.physicsEnabled = true; tilesprite = game.add.tileSprite(300, 450, 200, 100, 'starfield'); - tilesprite.body.immovable = true; - tilesprite.body.setRectangle(200, 100, 0, 0); + + tilesprite.physicsEnabled = true; + // tilesprite.body.immovable = true; + + // tilesprite.body.setRectangle(200, 100, 0, 0); cursors = game.input.keyboard.createCursorKeys(); @@ -29,8 +30,6 @@ function create() { function update() { - game.physics.collide(ball, tilesprite); - if (cursors.left.isDown) { tilesprite.x -= 8; @@ -55,6 +54,6 @@ function update() { function render() { - game.debug.renderPhysicsBody(tilesprite.body); + // game.debug.renderPhysicsBody(tilesprite); } \ No newline at end of file diff --git a/examples/time/basic looped event.js b/examples/time/basic looped event.js index 67deca0c..b0583c64 100644 --- a/examples/time/basic looped event.js +++ b/examples/time/basic looped event.js @@ -23,6 +23,7 @@ function create() { // The first parameter is how long to wait before the event fires. In this case 1 second (you could pass in 1000 as the value as well.) // The next two parameters are the function to call ('updateCounter') and the context under which that will happen. + game.time.events.loop(Phaser.Timer.SECOND, updateCounter, this); } @@ -31,7 +32,7 @@ function updateCounter() { counter++; - text.content = 'Counter: ' + counter; + text.setText('Counter: ' + counter); } diff --git a/examples/time/basic repeat event.js b/examples/time/basic repeat event.js index 63f15bee..44e5c288 100644 --- a/examples/time/basic repeat event.js +++ b/examples/time/basic repeat event.js @@ -33,9 +33,7 @@ function createBall() { var ball = game.add.sprite(game.world.randomX, 0, 'ball'); - ball.body.gravity.y = 200; - ball.body.bounce.y = 0.5; - ball.body.collideWorldBounds = true; + ball.physicsEnabled = true; } diff --git a/examples/time/remove event.js b/examples/time/remove event.js index ce755721..2b5df2c6 100644 --- a/examples/time/remove event.js +++ b/examples/time/remove event.js @@ -29,7 +29,7 @@ function updateCounter(idx) { counters[idx]++; - text[idx].content = 'Counter ' + idx + ' = ' + counters[idx]; + text[idx].setText('Counter ' + idx + ' = ' + counters[idx]); } @@ -42,7 +42,7 @@ function removeCounter() { // Just updates the text text[i].style.fill = '#3344aa'; - text[i].content = 'Counter ' + i + ' removed'; + text[i].setText('Counter ' + i + ' removed'); i--; } diff --git a/examples/wip/google webfont.js b/examples/wip/google webfont.js index 4b9f5ae7..51fd9897 100644 --- a/examples/wip/google webfont.js +++ b/examples/wip/google webfont.js @@ -19,7 +19,7 @@ WebFontConfig = { function preload() { // Load the Google WebFont Loader script - game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'); + game.load.script('webfont', 'http://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'); }