Jump to content

how to add a group in constructor ?


Recommended Posts


i'm searching to add my sprite in a group directly in my constructor function, but that don't work.

Have you some advice ?

Thanks in advance.


var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:preload, create: create });

function preload() {
   game.load.image('circle', 'https://s13.postimg.org/xjhlzmiev/disc_png.png');
   game.load.image('rect', 'http://s10.postimg.org/6fa6mgrd5/motif.jpg');
//E for external module
var E = E || {}
MonsterBunny = function (game, x, y, rotateSpeed,group) {

    Phaser.Sprite.call(this, game, x, y, 'rect');
    this.rotateSpeed = rotateSpeed;


MonsterBunny.prototype = Object.create(Phaser.Sprite.prototype);
MonsterBunny.prototype.constructor = MonsterBunny;

MonsterBunny.prototype.update = function() {

    this.angle += this.rotateSpeed;


E=E || {}

function create() {
    var thisgroup = game.add.group();
    var wabbit = new MonsterBunny(game,100,100,2,thisgroup)


Link to comment
Share on other sites

I think the problem is that you are adding the wabbit to game after you try to add it to the group

either add it to the group after game.add.existing(wabbit);


or move the game.add inside the constructor.

Not sure if there's another way to do it but that's all I can see wrong.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...