From 8dfe5aee1c88a53cc2517a7d147424c7d3645f2a Mon Sep 17 00:00:00 2001 From: Webeled Date: Fri, 25 Oct 2013 18:10:03 +0100 Subject: [PATCH] Second commit, all the basic examples added, and wip files moved --- examples/_site/examples.json | 44 +++++++++---------- examples/basics/02 - click on an image.js | 33 ++++++++++++++ examples/basics/03 - move an image.js | 24 ++++++++++ examples/basics/04 - image follow input.js | 35 +++++++++++++++ .../05 - load an animation.js} | 2 +- examples/basics/06 - render text.js | 11 +++++ examples/text/hello arial.js | 3 +- examples/{tilemaps => wip}/wip1.js | 0 examples/{tilemaps => wip}/wip2.js | 0 examples/{tilemaps => wip}/wip3.js | 0 examples/{tilemaps => wip}/wip4.js | 0 11 files changed, 125 insertions(+), 27 deletions(-) create mode 100644 examples/basics/02 - click on an image.js create mode 100644 examples/basics/03 - move an image.js create mode 100644 examples/basics/04 - image follow input.js rename examples/{animation/texture packer json hash.js => basics/05 - load an animation.js} (85%) create mode 100644 examples/basics/06 - render text.js rename examples/{tilemaps => wip}/wip1.js (100%) rename examples/{tilemaps => wip}/wip2.js (100%) rename examples/{tilemaps => wip}/wip3.js (100%) rename examples/{tilemaps => wip}/wip4.js (100%) diff --git a/examples/_site/examples.json b/examples/_site/examples.json index 88388bb0..19c6c41b 100644 --- a/examples/_site/examples.json +++ b/examples/_site/examples.json @@ -19,10 +19,6 @@ { "file": "sprite+sheet.js", "title": "sprite sheet" - }, - { - "file": "texture+packer+json+hash.js", - "title": "texture packer json hash" } ], "audio": [ @@ -43,6 +39,26 @@ { "file": "01+-+load+an+image.js", "title": "01 - load an image" + }, + { + "file": "02+-+click+on+an+image.js", + "title": "02 - click on an image" + }, + { + "file": "03+-+move+an+image.js", + "title": "03 - move an image" + }, + { + "file": "04+-+image+follow+input.js", + "title": "04 - image follow input" + }, + { + "file": "05+-+load+an+animation.js", + "title": "05 - load an animation" + }, + { + "file": "06+-+render+text.js", + "title": "06 - render text" } ], "buttons": [ @@ -504,10 +520,6 @@ "file": "bitmap+fonts.js", "title": "bitmap fonts" }, - { - "file": "hello+arial.js", - "title": "hello arial" - }, { "file": "kern+of+duty.js", "title": "kern of duty" @@ -575,22 +587,6 @@ { "file": "swap+tiles.js", "title": "swap tiles" - }, - { - "file": "wip1.js", - "title": "wip1" - }, - { - "file": "wip2.js", - "title": "wip2" - }, - { - "file": "wip3.js", - "title": "wip3" - }, - { - "file": "wip4.js", - "title": "wip4" } ], "tweens": [ diff --git a/examples/basics/02 - click on an image.js b/examples/basics/02 - click on an image.js new file mode 100644 index 00000000..56c8a0b5 --- /dev/null +++ b/examples/basics/02 - click on an image.js @@ -0,0 +1,33 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); + +function preload() { + + // You can fill the preloader with as many assets as your game requires + + // Here we are loading an image. The first parameter is the unique + // string by which we'll identify the image later in our code. + + // The second parameter is the URL of the image (relative) + game.load.image('einstein', 'assets/pics/ra_einstein.png'); +} + +function create() { + + // This creates a simple sprite that is using our loaded image and + // displays it on-screen + // and assign it to a variable + var image = game.add.sprite(0, 0, 'einstein'); + + //enables all kind of input actions on this image (click, etc) + image.inputEnabled=true; + + image.events.onInputDown.add(listener,this); + + + +} + +function listener () { + alert('clicked'); +} diff --git a/examples/basics/03 - move an image.js b/examples/basics/03 - move an image.js new file mode 100644 index 00000000..0cdd9320 --- /dev/null +++ b/examples/basics/03 - move an image.js @@ -0,0 +1,24 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); + +function preload() { + + // You can fill the preloader with as many assets as your game requires + + // Here we are loading an image. The first parameter is the unique + // string by which we'll identify the image later in our code. + + // The second parameter is the URL of the image (relative) + game.load.image('einstein', 'assets/pics/ra_einstein.png'); +} + +function create() { + + // This creates a simple sprite that is using our loaded image and + // displays it on-screen + // and assign it to a variable + var image = game.add.sprite(0, 0, 'einstein'); + + image.body.velocity.x=50; + +} diff --git a/examples/basics/04 - image follow input.js b/examples/basics/04 - image follow input.js new file mode 100644 index 00000000..64af7d3b --- /dev/null +++ b/examples/basics/04 - image follow input.js @@ -0,0 +1,35 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create,update:update,render:render }); + +function preload() { + + // You can fill the preloader with as many assets as your game requires + + // Here we are loading an image. The first parameter is the unique + // string by which we'll identify the image later in our code. + + // The second parameter is the URL of the image (relative) + game.load.image('cactuar', 'assets/pics/cactuar.png'); +} + +var image; + +function create() { + + // This creates a simple sprite that is using our loaded image and + // displays it on-screen + // and assign it to a variable + image = game.add.sprite(0, 0, 'cactuar'); + +} + +function update () { + + //magic formula to make an object follow the mouse + game.physics.moveToPointer(image,300,game.input.activePointer); +} + +function render () { + //debug helper + game.debug.renderInputInfo(32,32); +} diff --git a/examples/animation/texture packer json hash.js b/examples/basics/05 - load an animation.js similarity index 85% rename from examples/animation/texture packer json hash.js rename to examples/basics/05 - load an animation.js index 64c5e456..fb4d24c7 100644 --- a/examples/animation/texture packer json hash.js +++ b/examples/basics/05 - load an animation.js @@ -1,5 +1,5 @@ -var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create }); +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); function preload() { game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json'); diff --git a/examples/basics/06 - render text.js b/examples/basics/06 - render text.js new file mode 100644 index 00000000..bc3e56f7 --- /dev/null +++ b/examples/basics/06 - render text.js @@ -0,0 +1,11 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create }); + +function create() { + + var text = "- phaser -\n with a sprinkle of \n pixi dust."; + var style = { font: "65px Arial", fill: "#ff0044", align: "center" }; + + var t = game.add.text(game.world.centerX-300, 0, text, style); + +} diff --git a/examples/text/hello arial.js b/examples/text/hello arial.js index bd6e9934..df40c8cb 100644 --- a/examples/text/hello arial.js +++ b/examples/text/hello arial.js @@ -1,4 +1,3 @@ - var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create }); function create() { @@ -10,4 +9,4 @@ function create() { t.anchor.setTo(0.5, 0.5); -} +} \ No newline at end of file diff --git a/examples/tilemaps/wip1.js b/examples/wip/wip1.js similarity index 100% rename from examples/tilemaps/wip1.js rename to examples/wip/wip1.js diff --git a/examples/tilemaps/wip2.js b/examples/wip/wip2.js similarity index 100% rename from examples/tilemaps/wip2.js rename to examples/wip/wip2.js diff --git a/examples/tilemaps/wip3.js b/examples/wip/wip3.js similarity index 100% rename from examples/tilemaps/wip3.js rename to examples/wip/wip3.js diff --git a/examples/tilemaps/wip4.js b/examples/wip/wip4.js similarity index 100% rename from examples/tilemaps/wip4.js rename to examples/wip/wip4.js