Jump to content

extended sprite or sprites into a group?


small fish
 Share

Recommended Posts

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, ..).  The
difference between these two is GameObjectCreator adds the game object to
the 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 world
other game objects are its children
 
GameObjectCreator last parameter is group
its 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 objects
in the group hierarchy. Because it will still display but you might
get confused about positioning.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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