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

Add exclusive camera feature #6379

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rexrainbow
Copy link
Contributor

@rexrainbow rexrainbow commented Jan 31, 2023

Please do not update the README or Change Log, we will do this when we merge your PR.

This PR (delete as applicable)

  • Adds a new feature

Describe the changes below:

Exclusive camera will ignore all game objects, only render accepted game objects.

Test code

class Demo extends Phaser.Scene {
    constructor() {
        super({
            key: 'examples'
        })
    }

    preload() {
    }

    create() {
        var camera1 = this.cameras.main;

        var camera2 = this.cameras.add(400, 0, 400, 600)
            .setBackgroundColor(0x333333)
            .setExclusive();

        var gameObject0 = this.add.rectangle(200, 100, 100, 100, 0xffffff);
        var gameObject1 = this.add.rectangle(200, 400, 100, 100, 0xffffff);

        camera2.accept(gameObject0);
    }

    update() { }
}

var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    scale: {
        mode: Phaser.Scale.FIT,
        autoCenter: Phaser.Scale.CENTER_BOTH,
    },
    scene: Demo
};

Put gameObject0 on camera2, so it will only be rendered by camera2. And gameObject1 will only be rendered by camera1.

Exclusive camera will ignore all game objects, only render accepted game objects.
@@ -172,6 +172,21 @@ var GameObject = new Class({
*/
this.cameraFilter = 0;

/**
* A bitmask that controls if this Game Object is drawn by an exclusive Camera or not.
* Not usually set directly, instead call `Camera.accpet`, however you can
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a typo here: Camera.accept

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a typo here: Camera.accept

Thanks, had fixed this typo.

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

Successfully merging this pull request may close these issues.

None yet

2 participants