Skip to content

Commit ed13283

Browse files
committed
Tided up the cull / bounds demo.
1 parent 7c59799 commit ed13283

2 files changed

Lines changed: 35 additions & 30 deletions

File tree

examples/camera_cull1.php

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,48 @@
1515
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
1616

1717
function preload() {
18-
game.load.image('mushroom', 'assets/sprites/mana_card.png');
18+
game.load.image('disk', 'assets/sprites/ra_dont_crack_under_pressure.png');
1919
}
2020

2121
var s;
22-
var t;
2322

2423
function create() {
2524

26-
// Make our game world 2000x2000 pixels in size (the default is to match the game size)
27-
game.world.setSize(2000, 2000);
25+
game.world._stage.backgroundColorString = '#182d3b';
2826

29-
s = game.add.sprite(180, 400, 'mushroom');
30-
s.autoCull = true;
31-
32-
// s.visible = false;
33-
// t = game.time.now + 2000;
34-
// s.scrollFactor.setTo(0.5, 0.5);
27+
s = game.add.sprite(game.world.centerX, game.world.centerY, 'disk');
28+
s.anchor.setTo(0.5, 0.5);
3529

3630
}
3731

3832
function update() {
3933

40-
// if (game.time.now > t && s.visible == false)
41-
// {
42-
// console.log('visible');
43-
// s.visible = true;
44-
// }
45-
46-
// s.rotation += 0.01;
34+
s.rotation += 0.01;
4735

4836
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
4937
{
50-
game.camera.x -= 4;
38+
s.x -= 4;
5139
}
5240
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
5341
{
54-
game.camera.x += 4;
42+
s.x += 4;
5543
}
5644

5745
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
5846
{
59-
game.camera.y -= 4;
47+
s.y -= 4;
6048
}
6149
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
6250
{
63-
game.camera.y += 4;
51+
s.y += 4;
6452
}
6553

6654
}
6755

6856
function render() {
6957

70-
// game.debug.renderRectangle(game.world.camera.view, 'rgba(200,0,0,0.2)');
71-
// game.debug.renderRectangle(s.bounds);
72-
game.debug.renderSpriteCorners(s, true);
73-
74-
game.debug.renderSpriteInfo(s, 400, 32);
75-
game.debug.renderWorldTransformInfo(s, 32, 32);
76-
// game.debug.renderLocalTransformInfo(s, 200, 32);
77-
game.debug.renderCameraInfo(game.world.camera, 32, 200);
58+
game.debug.renderSpriteCorners(s, true, true);
59+
game.debug.renderSpriteInfo(s, 20, 32);
7860

7961
}
8062

src/utils/Debug.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,40 @@ Phaser.Utils.Debug.prototype = {
105105

106106
},
107107

108-
renderSpriteCorners: function (sprite, showText, color) {
108+
renderSpriteCorners: function (sprite, showText, showBounds, color) {
109109

110110
if (this.context == null)
111111
{
112112
return;
113113
}
114114

115115
showText = showText || false;
116+
showBounds = showBounds || false;
116117
color = color || 'rgb(255,0,255)';
117118

118119
this.start(0, 0, color);
120+
121+
if (showBounds)
122+
{
123+
this.context.beginPath();
124+
this.context.moveTo(sprite.bounds.x, sprite.bounds.y);
125+
this.context.lineTo(sprite.bounds.x + sprite.bounds.width, sprite.bounds.y);
126+
this.context.lineTo(sprite.bounds.x + sprite.bounds.width, sprite.bounds.y + sprite.bounds.height);
127+
this.context.lineTo(sprite.bounds.x, sprite.bounds.y + sprite.bounds.height);
128+
this.context.closePath();
129+
this.context.strokeStyle = 'rgba(255,0,255,0.5)';
130+
this.context.stroke();
131+
}
132+
133+
this.context.beginPath();
134+
this.context.moveTo(sprite.topLeft.x, sprite.topLeft.y);
135+
this.context.lineTo(sprite.topRight.x, sprite.topRight.y);
136+
this.context.lineTo(sprite.bottomRight.x, sprite.bottomRight.y);
137+
this.context.lineTo(sprite.bottomLeft.x, sprite.bottomLeft.y);
138+
this.context.closePath();
139+
this.context.strokeStyle = 'rgba(0,0,255,0.8)';
140+
this.context.stroke();
141+
119142
this.renderPoint(sprite.topLeft);
120143
this.renderPoint(sprite.topRight);
121144
this.renderPoint(sprite.bottomLeft);

0 commit comments

Comments
 (0)