From ed13283f0f81f137b87dc4e228173442195712f2 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 3 Sep 2013 00:42:17 +0100 Subject: [PATCH] Tided up the cull / bounds demo. --- examples/camera_cull1.php | 40 +++++++++++---------------------------- src/utils/Debug.js | 25 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/examples/camera_cull1.php b/examples/camera_cull1.php index 9a22eef9..d332703b 100644 --- a/examples/camera_cull1.php +++ b/examples/camera_cull1.php @@ -15,66 +15,48 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render }); function preload() { - game.load.image('mushroom', 'assets/sprites/mana_card.png'); + game.load.image('disk', 'assets/sprites/ra_dont_crack_under_pressure.png'); } var s; - var t; function create() { - // Make our game world 2000x2000 pixels in size (the default is to match the game size) - game.world.setSize(2000, 2000); + game.world._stage.backgroundColorString = '#182d3b'; - s = game.add.sprite(180, 400, 'mushroom'); - s.autoCull = true; - - // s.visible = false; - // t = game.time.now + 2000; - // s.scrollFactor.setTo(0.5, 0.5); + s = game.add.sprite(game.world.centerX, game.world.centerY, 'disk'); + s.anchor.setTo(0.5, 0.5); } function update() { - // if (game.time.now > t && s.visible == false) - // { - // console.log('visible'); - // s.visible = true; - // } - - // s.rotation += 0.01; + s.rotation += 0.01; if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { - game.camera.x -= 4; + s.x -= 4; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { - game.camera.x += 4; + s.x += 4; } if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { - game.camera.y -= 4; + s.y -= 4; } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { - game.camera.y += 4; + s.y += 4; } } function render() { - // game.debug.renderRectangle(game.world.camera.view, 'rgba(200,0,0,0.2)'); - // game.debug.renderRectangle(s.bounds); - game.debug.renderSpriteCorners(s, true); - - game.debug.renderSpriteInfo(s, 400, 32); - game.debug.renderWorldTransformInfo(s, 32, 32); - // game.debug.renderLocalTransformInfo(s, 200, 32); - game.debug.renderCameraInfo(game.world.camera, 32, 200); + game.debug.renderSpriteCorners(s, true, true); + game.debug.renderSpriteInfo(s, 20, 32); } diff --git a/src/utils/Debug.js b/src/utils/Debug.js index c95c998e..db3b67f7 100644 --- a/src/utils/Debug.js +++ b/src/utils/Debug.js @@ -105,7 +105,7 @@ Phaser.Utils.Debug.prototype = { }, - renderSpriteCorners: function (sprite, showText, color) { + renderSpriteCorners: function (sprite, showText, showBounds, color) { if (this.context == null) { @@ -113,9 +113,32 @@ Phaser.Utils.Debug.prototype = { } showText = showText || false; + showBounds = showBounds || false; color = color || 'rgb(255,0,255)'; this.start(0, 0, color); + + if (showBounds) + { + this.context.beginPath(); + this.context.moveTo(sprite.bounds.x, sprite.bounds.y); + this.context.lineTo(sprite.bounds.x + sprite.bounds.width, sprite.bounds.y); + this.context.lineTo(sprite.bounds.x + sprite.bounds.width, sprite.bounds.y + sprite.bounds.height); + this.context.lineTo(sprite.bounds.x, sprite.bounds.y + sprite.bounds.height); + this.context.closePath(); + this.context.strokeStyle = 'rgba(255,0,255,0.5)'; + this.context.stroke(); + } + + this.context.beginPath(); + this.context.moveTo(sprite.topLeft.x, sprite.topLeft.y); + this.context.lineTo(sprite.topRight.x, sprite.topRight.y); + this.context.lineTo(sprite.bottomRight.x, sprite.bottomRight.y); + this.context.lineTo(sprite.bottomLeft.x, sprite.bottomLeft.y); + this.context.closePath(); + this.context.strokeStyle = 'rgba(0,0,255,0.8)'; + this.context.stroke(); + this.renderPoint(sprite.topLeft); this.renderPoint(sprite.topRight); this.renderPoint(sprite.bottomLeft);