mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 22:18:29 +00:00
Tided up the cull / bounds demo.
This commit is contained in:
parent
7c597999d4
commit
ed13283f0f
2 changed files with 35 additions and 30 deletions
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue