Skip to content

Commit 7c59799

Browse files
committed
Camera culling now in and working, although you need to enable it on a per sprite basis. Also fixed a few small bugs in the Animation Manager.
1 parent 6235f25 commit 7c59799

4 files changed

Lines changed: 222 additions & 162 deletions

File tree

examples/camera_cull1.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@
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/mushroom2.png');
18+
game.load.image('mushroom', 'assets/sprites/mana_card.png');
1919
}
2020

2121
var s;
22+
var t;
2223

2324
function create() {
2425

2526
// Make our game world 2000x2000 pixels in size (the default is to match the game size)
2627
game.world.setSize(2000, 2000);
2728

28-
s = game.add.sprite(800, 400, 'mushroom');
29+
s = game.add.sprite(180, 400, 'mushroom');
30+
s.autoCull = true;
31+
32+
// s.visible = false;
33+
// t = game.time.now + 2000;
2934
// s.scrollFactor.setTo(0.5, 0.5);
3035

3136
}
3237

3338
function update() {
3439

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

3748
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
@@ -56,10 +67,13 @@ function update() {
5667

5768
function render() {
5869

59-
game.debug.renderRectangle(game.world.camera.view, 'rgba(200,0,0,0.2)');
60-
game.debug.renderRectangle(s.bounds);
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);
6173

62-
game.debug.renderSpriteInfo(s, 32, 32);
74+
game.debug.renderSpriteInfo(s, 400, 32);
75+
game.debug.renderWorldTransformInfo(s, 32, 32);
76+
// game.debug.renderLocalTransformInfo(s, 200, 32);
6377
game.debug.renderCameraInfo(game.world.camera, 32, 200);
6478

6579
}

src/animation/AnimationManager.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Phaser.AnimationManager = function (parent) {
3232

3333
Phaser.AnimationManager.prototype = {
3434

35+
updateIfVisible: true,
36+
3537
/**
3638
* Load animation frame data.
3739
* @param frameData Data to be loaded.
@@ -54,10 +56,10 @@ Phaser.AnimationManager.prototype = {
5456
*/
5557
add: function (name, frames, frameRate, loop, useNumericIndex) {
5658

57-
if (typeof frames === "undefined") { frames = null; }
58-
if (typeof frameRate === "undefined") { frameRate = 60; }
59-
if (typeof loop === "undefined") { loop = false; }
60-
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
59+
frames = frames || null;
60+
frameRate = frameRate || 60;
61+
loop = loop || false;
62+
useNumericIndex = useNumericIndex || true;
6163

6264
if (this._frameData == null)
6365
{
@@ -138,8 +140,8 @@ Phaser.AnimationManager.prototype = {
138140
*/
139141
play: function (name, frameRate, loop) {
140142

141-
if (typeof frameRate === "undefined") { frameRate = null; }
142-
if (typeof loop === "undefined") { loop = null; }
143+
frameRate = frameRate || null;
144+
loop = loop || null;
143145

144146
if (this._anims[name])
145147
{
@@ -178,6 +180,11 @@ Phaser.AnimationManager.prototype = {
178180
*/
179181
update: function () {
180182

183+
if (this.updateIfVisible && this._parent.visible == false)
184+
{
185+
return;
186+
}
187+
181188
if (this.currentAnim && this.currentAnim.update() == true)
182189
{
183190
this.currentFrame = this.currentAnim.currentFrame;
@@ -231,7 +238,12 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", {
231238
Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
232239

233240
get: function () {
234-
return this._frameIndex;
241+
242+
if (this.currentFrame)
243+
{
244+
return this._frameIndex;
245+
}
246+
235247
},
236248

237249
/**
@@ -256,7 +268,12 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
256268
Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
257269

258270
get: function () {
259-
return this.currentFrame.name;
271+
272+
if (this.currentFrame)
273+
{
274+
return this.currentFrame.name;
275+
}
276+
260277
},
261278

262279
set: function (value) {

0 commit comments

Comments
 (0)