Klaus Posted May 2, 2015 Share Posted May 2, 2015 Hey there,I'm wondering if there's some kind of game object structure where a single object of the scene graph can hold custom scripts in addition to display objects. I'm thinking of Unity like game objects that can have display objects (like sprites) but also behavioural components all on the same scene-graph node. So far I only know of the scene graph that holds DisplayObjects that can be grouped together. Is there another set of functions built into phaser for adding and retrieving behaviour scripts to that? If so, can you point me to the right direction by giving a few key-words to look for?Thanks and cheers Link to comment Share on other sites More sharing options...
Tom Atom Posted May 2, 2015 Share Posted May 2, 2015 Easy way is to derive from standard Phaser objects. Derive from Sprite and add additional functionality to it. Such object is also still Sprite and you can put it into scene hierarchy similar to Unity (where everything in scene hierarchy has/is Transform). Link to comment Share on other sites More sharing options...
drhayes Posted May 4, 2015 Share Posted May 4, 2015 You might want to look at Phaser.Plugin, too. It's a great way to get an object that gets its update method called from within the game loop. If you make a CatpantsPlugin like this:function Catpants(game, parent) { Phaser.Plugin.call(this, game, parent);}Catpants.prototype = Object.create(Phaser.Plugin.prototype);Catpants.prototype.constructor = CatpantsCatpants.prototype.update = function() { // Stuff goes here...}You would register this plugin like this:game.plugins.add(CatpantsPlugin);Don't call new on it or anything, the PluginManager will do that for you. Link to comment Share on other sites More sharing options...
Recommended Posts