ObjectFactory Class
The object factory makes it simple to create and add objects to a parent. One is added to a State's world and camera by default, but they can be used for any parent but they can only belong to a single state.
Constructor
Methods
audio
-
key
-
[settings]
Creates a new AudioPlayer to play the sound passed in
Parameters:
-
key
StringThe unique cache key for the preloaded audio
-
[settings]
Object optionalAll the settings for the audio player (see AudioManager.add for all settings)
Returns:
The player added
bitmaptext
-
text
-
font
-
interactive
Creates a new instance of BitmapText
Parameters:
-
text
StringThe text for the BitmapText to display
-
font
StringThe key for the bitmap font loaded into the cache
-
interactive
BooleanCan the item be interacted with by mouse (clicked, dragged, etc)
Returns:
The bitmap text object added
gui
-
texture
-
interactive
Creates a new gui item and adds it to the Camera's GUI
Parameters:
-
texture
String | TextureThe texture for the item, or the key for one in the cache
-
interactive
BooleanCan the item be interacted with by mouse (clicked, dragged, etc)
Returns:
The new gui item added
obj
-
object
Adds a generic object to the world or camera
Parameters:
-
object
MixedAny game object you want to add to the parent
Returns:
Returns the added object
sprite
-
texture
-
[frame=null]
-
[physics=true]
Creates a new sprite and adds it to the game world
Parameters:
-
texture
String | TextureThe texture for the sprite, or the key for one in the cache
-
[frame=null]
String | Number optionalA specific frame of a sprite sheet to use, either the index or string key depending on the type of the sheet when loaded.
-
[physics=true]
Boolean optionalShould this sprite be added to the physics simulation?
Returns:
The sprite added