Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game.camera not updated by Game.prototype.switchState() #14

Closed
HackManiac opened this issue Apr 28, 2013 · 1 comment
Closed

Game.camera not updated by Game.prototype.switchState() #14

HackManiac opened this issue Apr 28, 2013 · 1 comment

Comments

@HackManiac
Copy link
Contributor

When Game.prototype.switchState() is called, it calls CameraManager.prototype.destroy() which creates and assigns a new camera to its current instance variable, but the camera instance variable in the Game instance is not updated.

Wouldn't it make sense to use a getter instead of an camera instance variable for the Game class, like this:

public get camera(): Camera {
  return this.world._cameras.current;
}

That way you do not have to keep it in sync manually.

The code that helped detect the problem:

    Phaser.Game.prototype.transitionToState = function(state, color, duration, completeCallback) {
        if (color == null) {
            color = 0x000000;
        }
        if (duration == null) {
            duration = 0.6;
        }

        var _this = this;

        var debugCameras = function(msg) {
            var id1 = _this.camera;
            id1 = id1 && id1.ID;
            var id2 = _this.world;
            id2 = id2 && id2._cameras;
            id2 = id2 && id2.current;
            id2 = id2 && id2.ID;

            console.log('--- ', msg, ' ---');
            console.log(_this.time && _this.time.now);
            console.log('Game#camera.ID: ', id1);
            console.log('Game#world._cameras.current.ID: ', id2);
        };

        var onFadeCompleted = function() {
            debugCameras('Before switchState');
            _this.switchState(state);
            debugCameras('Before flash');
            _this.camera.flash(color, duration / 2, onFlashCompleted);
        };

        var onFlashCompleted = function() {
            debugCameras('After transition');
            completeCallback();
        };

        if (_this.camera) {
            debugCameras('Before fade');
            _this.camera.fade(color, duration / 2, onFadeCompleted);
        } else {
            onFadeCompleted();
        }
    };

That code above behaves differently depending on when and how often it is called. But the third and all following calls to the function print out the "Before fade" message and then do nothing at all, since the fade is called on the wrong Camera instance.

@photonstorm
Copy link
Collaborator

Agreed, good idea. Have made World._cameras public at World.cameras and Game.camera is now a getter for World.cameras.current - this is now in 0.9.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants