mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Added examples group: Debug tools
This commit is contained in:
parent
9a968bc5bb
commit
e103d6ae83
6 changed files with 234 additions and 0 deletions
40
examples/debug/debug camera.js
Normal file
40
examples/debug/debug camera.js
Normal file
|
@ -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);
|
||||
|
||||
}
|
41
examples/debug/debug display.js
Normal file
41
examples/debug/debug display.js
Normal file
|
@ -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);
|
||||
|
||||
}
|
18
examples/debug/debug draw.js
Normal file
18
examples/debug/debug draw.js
Normal file
|
@ -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 );
|
||||
|
||||
|
||||
}
|
41
examples/debug/debug input.js
Normal file
41
examples/debug/debug input.js
Normal file
|
@ -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 );
|
||||
|
||||
}
|
53
examples/debug/debug physics.js
Normal file
53
examples/debug/debug physics.js
Normal file
|
@ -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);
|
||||
|
||||
}
|
41
examples/debug/debug sprite.js
Normal file
41
examples/debug/debug sprite.js
Normal file
|
@ -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);
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue