Jump to content

How add a PIXI container into a Phaser Game?


artsjedi
 Share

Recommended Posts

How add a PIXI container into a Phaser Game?

I have a game made ONLY with PIXI. but now i would like to port it to a Phaser.

All my game content happens inside a pixi container "screenContainer".  I tried to add a pixi container like this.

var created = function() {
       screenContainer = new PIXI.DisplayObjectContainer();
       var sprite = m.game.add.existing(screenContainer);
}

var.game = new Phaser.Game(gameWidth, gameHeight, Phaser.AUTO, "divId", { create: created }); 

but it stops here

"phaser.js" line 33067

/**
* The core update - as called by World.
* @method Phaser.Group#update
* @protected
*/
Phaser.Group.prototype.update = function () {

    var i = this.children.length;

    while (i--)
    {
        this.children[i].update(); // UPDATE IS UNDEFINED
    }

};

because Pixi.Container, does not have "update" method.

Is there any other way to add a pixi container inside a phaser game?

 

thanks

Link to comment
Share on other sites

this does not works. I understand that Phaser.Group extends the current PIXI.Container. However my old project is a PIXI one. I would like to make this work with Phaser.

var game = new Phaser.Game(500, 600, Phaser.AUTO, "divId", { create: created })//,  preload: preload,  update: update, render:render }); 

function created() { 
    var screenContainer = game.add.group()
    var otherContainer = new PIXI.DisplayObjectContainer(); // it MUST be a PIXI object, not a Phaser one.
    screenContainer.addChild(otherContainer)
}

this simple does not works.

Link to comment
Share on other sites

Either modify your DisplayObjectContainer base class to include the required functions and properties, so they can be iterated and treated as first class citizens within a Group, or create a new class that does have these things in them, that extends DisplayObjectContainer, and modify your game code to create those instead. Off the top of my head there are only 3 methods, and I think 2 properties that are required in order to be a valid child of a Group - they're defined in the Core component.

 

Link to comment
Share on other sites

Thanks, I solved adding this simple patch.

PIXI.DisplayObject.prototype.update = function () { };
PIXI.DisplayObject.prototype.postUpdate = function () { };

this patch adds a empty function for "update" and "postUpdate" methods in PIXI displayObjects prototype. In that case Phaser update tree founds a function to execute.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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