small fish Posted July 7, 2014 Share Posted July 7, 2014 is it possible? Link to comment Share on other sites More sharing options...
eguneys Posted July 7, 2014 Share Posted July 7, 2014 Do you mean like thisvar mySprite = new ExtendedSprite();myGroup.add(mySprite); small fish 1 Link to comment Share on other sites More sharing options...
small fish Posted July 7, 2014 Author Share Posted July 7, 2014 yes like that. But oh, I was using game.create( 0,0, my sprite). I thoughtmyGroup.add() was just for adding groups to groups. No? I will try. Thanks! Link to comment Share on other sites More sharing options...
eguneys Posted July 7, 2014 Share Posted July 7, 2014 Things are tricky when i started.// Creates a sprite with the key and// adds the sprite to the groupgroup.create(0, 0, key, frame);// Adds any game object to the group (Sprite, Group, Graphics, ..)group.add(anyGameObject);//So if you have a base sprite with a key//this creates the sprite and add it to the group.//group.create(0, 0, key, frame);//but if you have an extended sprite//you have to first create the sprite yourselfvar sprite = new ExtendedSprite();//then add it manually.group.add(sprite);//or you can add any game object as wellgroup.add(anyGameObject);One more related thing is about `game.add` and `game.make` `game.make` is a GameObjectFactory (http://docs.phaser.io/Phaser.Game.html#make) `game.add` is a GameObjectCreator (http://docs.phaser.io/Phaser.Game.html#add) These both create game objects (Sprite, Group, Graphics, ..). Thedifference between these two is GameObjectCreator adds the game object tothe group you specify in addition to creating them. So you call functions on GameObjectFactory and GameObjectCreator// game.add is GameObjectCreator// this will create a sprite, then add it to the groupgame.add.sprite(0, 0, key, frame, group)// game.make is GameObjectFactory// this will just create a spritevar mySprite = game.make.sprite(0, 0, key, frame)// so you can manually add itmyGroup.add(mySprite);The default root group is game worldother game objects are its childrenhttp://docs.phaser.io/Phaser.Game.html#world GameObjectCreator last parameter is groupits optional, if you don't specify it, it will add the sprite to the game world.So you have to be careful about where you add your game objectsin the group hierarchy. Because it will still display but you mightget confused about positioning. lewster32 1 Link to comment Share on other sites More sharing options...
small fish Posted July 7, 2014 Author Share Posted July 7, 2014 Thanks again for the detailed explanation. Good to know about world being the root group. Starting to make more sense Link to comment Share on other sites More sharing options...
Recommended Posts