From 9a968bc5bb90c4ec67f9ccf411260d6893e42a30 Mon Sep 17 00:00:00 2001 From: "inductible.dev" Date: Mon, 23 Dec 2013 09:48:07 +0000 Subject: [PATCH 1/3] TypeScript defs: TileSprite now extends Sprite, and added 'fixedToCamera' property to Sprite definition --- build/phaser.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/phaser.d.ts b/build/phaser.d.ts index 9a57431b..ee697f41 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -743,6 +743,7 @@ declare module Phaser { crop: boolean; cropEnabled: boolean; inputEnabled: boolean; + fixedToCamera:boolean; preUpdate(): void; postUpdate(): void; centerOn(x: number, y: number): void; @@ -777,7 +778,7 @@ declare module Phaser { onAnimationLoop: Phaser.Signal; } - class TileSprite { + class TileSprite extends Sprite { constructor(game: Phaser.Game, x: number, y: number, width: number, height: number, key?: string, frame?: number); texture: Phaser.RenderTexture; type: number; From e103d6ae8302f4139ff8c01796800a4b3398c9ad Mon Sep 17 00:00:00 2001 From: "inductible.dev" Date: Mon, 23 Dec 2013 15:59:26 +0000 Subject: [PATCH 2/3] Added examples group: Debug tools --- examples/debug/debug camera.js | 40 +++++++++++++++++++++++++ examples/debug/debug display.js | 41 +++++++++++++++++++++++++ examples/debug/debug draw.js | 18 +++++++++++ examples/debug/debug input.js | 41 +++++++++++++++++++++++++ examples/debug/debug physics.js | 53 +++++++++++++++++++++++++++++++++ examples/debug/debug sprite.js | 41 +++++++++++++++++++++++++ 6 files changed, 234 insertions(+) create mode 100644 examples/debug/debug camera.js create mode 100644 examples/debug/debug display.js create mode 100644 examples/debug/debug draw.js create mode 100644 examples/debug/debug input.js create mode 100644 examples/debug/debug physics.js create mode 100644 examples/debug/debug sprite.js diff --git a/examples/debug/debug camera.js b/examples/debug/debug camera.js new file mode 100644 index 00000000..8a33c50a --- /dev/null +++ b/examples/debug/debug camera.js @@ -0,0 +1,40 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update:update, render:render }); + +var sprite, spriteB ; +var counter = 0 ; +var step = Math.PI * 2 / 360 ; + + +function preload() { + + // Load images to use as the game sprites + game.load.image('sprite', 'assets/sprites/phaser2.png'); + +} + +function create() { + + // Create sprite and put it in the middle of the stage + sprite = game.add.sprite(0, 0, 'sprite'); + sprite.alpha = 0.5 ; + sprite.x = game.width / 2 ; + sprite.anchor.x = sprite.anchor.y = 0.5 ; + +} + +function update() +{ + // Move sprite up and down smoothly for show + var tStep = Math.sin( counter ) ; + sprite.y = (game.height/2) + tStep * 30 ; + sprite.rotation += Phaser.Math.degToRad( 0.1 * tStep ) ; + counter += step ; +} + +function render() { + + // Camera + game.debug.renderCameraInfo(game.camera, 32, 32); + +} diff --git a/examples/debug/debug display.js b/examples/debug/debug display.js new file mode 100644 index 00000000..6c0a9669 --- /dev/null +++ b/examples/debug/debug display.js @@ -0,0 +1,41 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update:update, render:render }); + +var sprite ; +var counter = 0 ; +var step = Math.PI * 2 / 360 ; + + +function preload() { + + // Load images to use as the game sprites + game.load.image('sprite', 'assets/sprites/phaser2.png'); + +} + +function create() { + + // Create sprite and put it in the middle of the stage + sprite = game.add.sprite(0, 0, 'sprite'); + sprite.alpha = 0.5 ; + sprite.x = game.width / 2 ; + sprite.anchor.x = sprite.anchor.y = 0.5 ; + +} + +function update() +{ + // Move sprite up and down smoothly for show + var tStep = Math.sin( counter ) ; + sprite.y = (game.height/2) + tStep * 30 ; + sprite.rotation += Phaser.Math.degToRad( 0.1 * tStep ) ; + counter += step ; +} + +function render() { + + // Display + game.debug.renderSpriteBounds(sprite); + game.debug.renderSpriteCorners(sprite, true, true); + +} diff --git a/examples/debug/debug draw.js b/examples/debug/debug draw.js new file mode 100644 index 00000000..5c303229 --- /dev/null +++ b/examples/debug/debug draw.js @@ -0,0 +1,18 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { render:render }); + +var rect = new Phaser.Rectangle( 100, 100, 100, 100 ) ; +var circle = new Phaser.Circle( 280, 150, 100 ) ; +var point = new Phaser.Point( 100, 280 ) ; + +function render() { + + // Draw debug tools + game.debug.renderRectangle( rect, 'rgba(255,0,0,1)' ) ; + game.debug.renderCircle( circle, 'rgba(255,255,0,1)' ) ; + game.debug.renderPoint( point, 'rgba(255,255,255,1)' ) ; + game.debug.renderPixel( 200, 280, 'rgba(0,255,255,1)' ) ; + game.debug.renderText( "This is debug text", 100, 380 ); + + +} diff --git a/examples/debug/debug input.js b/examples/debug/debug input.js new file mode 100644 index 00000000..14242a8b --- /dev/null +++ b/examples/debug/debug input.js @@ -0,0 +1,41 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update:update, render:render }); + +var sprite ; +var counter = 0 ; +var step = Math.PI * 2 / 360 ; + +function preload() { + + // Load images to use as the game sprites + game.load.image('sprite', 'assets/sprites/phaser2.png'); + +} + +function create() { + + // Create sprite and put it in the middle of the stage + 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.inputEnabled = true ; +} + +function update() +{ + // Move sprite up and down smoothly for show + var tStep = Math.sin( counter ) ; + sprite.y = (game.height/2) + tStep * 30 ; + sprite.rotation += Phaser.Math.degToRad( 0.1 * tStep ) ; + counter += step ; +} + +function render() { + + // Input debug info + game.debug.renderInputInfo(32, 32); + game.debug.renderSpriteInputInfo(sprite, 32, 130); + game.debug.renderPointer( game.input.activePointer ); + +} diff --git a/examples/debug/debug physics.js b/examples/debug/debug physics.js new file mode 100644 index 00000000..01bab7d8 --- /dev/null +++ b/examples/debug/debug physics.js @@ -0,0 +1,53 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update:update, render:render }); + +var sprite, otherSprite ; +var counter = 0 ; +var step = Math.PI * 2 / 360 ; + + +function preload() { + + // Load images to use as the game sprites + game.load.image('sprite', 'assets/sprites/phaser2.png'); + game.load.image('otherSprite', 'assets/sprites/phaser-dude.png'); + +} + +function create() { + + // Create sprite A and put it in the middle of the stage + sprite = game.add.sprite(0, 0, 'sprite'); + sprite.alpha = 0.5 ; + sprite.x = game.width / 2 ; + sprite.anchor.x = sprite.anchor.y = 0.5 ; + + // 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.body.immovable = true ; +} + +function update() +{ + game.physics.collide( sprite, otherSprite ) ; + + // Move sprite up and down smoothly for show + var tStep = Math.sin( counter ) ; + sprite.y = (game.height/2) + tStep * 30 ; + sprite.rotation += Phaser.Math.degToRad( 0.1 * tStep ) ; + counter += step ; +} + +function render() { + + // Physics + game.debug.renderSpriteBody(sprite); + game.debug.renderSpriteCollision(sprite, 32, 32); + + game.debug.renderSpriteBody(otherSprite); + +} diff --git a/examples/debug/debug sprite.js b/examples/debug/debug sprite.js new file mode 100644 index 00000000..4ebfe778 --- /dev/null +++ b/examples/debug/debug sprite.js @@ -0,0 +1,41 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update:update, render:render }); + +var sprite ; +var counter = 0 ; +var step = Math.PI * 2 / 360 ; + + +function preload() { + + // Load images to use as the game sprites + game.load.image('sprite', 'assets/sprites/phaser2.png'); + +} + +function create() { + + // Create sprite and put it in the middle of the stage + sprite = game.add.sprite(0, 0, 'sprite'); + sprite.alpha = 0.5 ; + sprite.x = game.width / 2 ; + sprite.anchor.x = sprite.anchor.y = 0.5 ; +} + +function update() +{ + // Move sprite up and down smoothly for show + var tStep = Math.sin( counter ) ; + sprite.y = (game.height/2) + tStep * 30 ; + sprite.rotation += Phaser.Math.degToRad( 0.1 * tStep ) ; + counter += step ; +} + +function render() { + + // Sprite debug info + game.debug.renderSpriteInfo(sprite, 32, 32); + game.debug.renderLocalTransformInfo(sprite, 32, 160); + game.debug.renderWorldTransformInfo(sprite, 32, 290); + +} From 7acf79338c847f083a327bf0e9327310ad8f152e Mon Sep 17 00:00:00 2001 From: "inductible.dev" Date: Mon, 23 Dec 2013 15:59:58 +0000 Subject: [PATCH 3/3] Added examples group: Debug tools --- examples/_site/examples.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/examples/_site/examples.json b/examples/_site/examples.json index 55124fa8..259eff31 100644 --- a/examples/_site/examples.json +++ b/examples/_site/examples.json @@ -177,6 +177,28 @@ "title": "render texture trail" } ], + "debug":[ + { + "file": "debug+sprite.js", + "title": "Sprite data" + }, + { + "file": "debug+display.js", + "title": "Sprite display" + }, + { + "file": "debug+input.js", + "title": "Input" + }, + { + "file": "debug+camera.js", + "title": "Camera" + }, + { + "file": "debug+draw.js", + "title": "Draw" + } + ], "filters": [ { "file": "blur.js",