artsjedi

How add a PIXI container into a Phaser Game?

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

Share this post


Link to post
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.

Share this post


Link to post
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.

 

Share this post


Link to post
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.

Share this post


Link to post
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.

Guest
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.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.