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.add.spriteBatch parameters suggestion #1000

Closed
petarov opened this issue Jul 11, 2014 · 2 comments
Closed

game.add.spriteBatch parameters suggestion #1000

petarov opened this issue Jul 11, 2014 · 2 comments

Comments

@petarov
Copy link
Contributor

petarov commented Jul 11, 2014

From the SpriteBatch docs:

new SpriteBatch(game, parent, name, addToStage)
parent - ... If undefined or null it will use game.world.

This is a simple suggestion that allows for the parent parameter to be skipped, therefore adding the SpriteBatch directly to game.world.

In GameObjectFactory

    spriteBatch: function (parent, name, addToStage) {
        if (typeof parent === 'string') {
            addToStage = typeof name === 'boolean' ? name : addToStage;
            name = parent;
            parent = undefined;
        }
        if (typeof name === 'undefined') { name = 'group'; }
        if (typeof addToStage === 'undefined') { addToStage = false; }

        return new Phaser.SpriteBatch(this.game, parent, name, addToStage);

    },

e.g.,

this.game.add.spriteBatch('batch');
this.game.add.spriteBatch('batch', false);
@photonstorm
Copy link
Collaborator

Thanks for the suggestion. I don't like using optional parameters, but I have implemented what you requested - you can now simply pass 'null' as the parent and it will default to game.world. Or if you pass no parameters at all it will do the same.

photonstorm added a commit that referenced this issue Jul 14, 2014
…ter for the parent and automatically adds the batch to `game.world` as a result. Also fixed jsdocs issues (@petarov #1000)
@petarov
Copy link
Contributor Author

petarov commented Jul 14, 2014

ok, should be fine, thx! I think I don't need to explicitly set a name to the group, at least in my case.

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