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; diff --git a/examples/_site/examples.json b/examples/_site/examples.json index cc779cba..95bd0bba 100644 --- a/examples/_site/examples.json +++ b/examples/_site/examples.json @@ -181,6 +181,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", 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); + +}