artsjedi Posted May 9, 2016 Share Posted May 9, 2016 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 More sharing options...
rich Posted May 10, 2016 Share Posted May 10, 2016 Phaser.Group = DisplayObjectContainer Link to comment Share on other sites More sharing options...
artsjedi Posted May 10, 2016 Author Share Posted May 10, 2016 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 More sharing options...
rich Posted May 10, 2016 Share Posted May 10, 2016 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. artsjedi 1 Link to comment Share on other sites More sharing options...
artsjedi Posted May 10, 2016 Author Share Posted May 10, 2016 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 More sharing options...
Recommended Posts