Constructor
new World(game)
The world container stores every sprite or group and updates them automatically. It is managed automatically by Carrot.Game.
Parameters:
Name | Type | Description |
---|---|---|
game |
Carrot.Game | The core game object. |
Methods
addChild(entity)
Adds a child to the world container. The child can be a sprite or a group.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Carrot.Group | Carrot.Sprite | The entity to add. |
create(xopt, yopt, keyopt, frameopt, activeopt) → {Carrot.Sprite}
Creates a sprite and immediately adds it to the world container.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
integer |
<optional> |
0 | The x coordinate in the world of the sprite. |
y |
integer |
<optional> |
0 | The y coordinate in the world of the sprite. |
key |
string |
<optional> |
null | This is the image for the sprite. If left empty, the sprite will be just a green rectangle. |
frame |
integer |
<optional> |
0 | Only for spritesheets: The starting frame of the image. If not passed, it will be 0, the first frame. |
active |
boolean |
<optional> |
false | The default active property of the sprite. |
Returns:
- Type
- Carrot.Sprite
createMultiple(quantityopt, xopt, yopt, keyopt, frameopt, activeopt) → {array}
Creates multiple sprites and adds them to the world container.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
quantity |
integer |
<optional> |
1 | The x coordinate in the world of the sprite. |
x |
integer |
<optional> |
0 | The x coordinate in the world of the sprite. |
y |
integer |
<optional> |
0 | The y coordinate in the world of the sprite. |
key |
string |
<optional> |
null | This is the image for the sprite. If left empty, the sprite will be just a green rectangle. |
frame |
integer |
<optional> |
0 | Only for spritesheets: The starting frame of the image. If not passed, it will be 0, the first frame. |
active |
boolean |
<optional> |
false | The default active property of the sprites. |
Returns:
- Type
- array
removeChild(entity)
Removes the given child from the world container.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Carrot.Group | Carrot.Sprite | The child to remove. |
setBounds(xopt, yopt, widthopt, heightopt)
Sets the size (bounds) of the game world.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
integer |
<optional> |
0 | The left bound of the world. |
y |
integer |
<optional> |
0 | The top bound of the world. |
width |
integer |
<optional> |
800 | The right bound of the world. |
height |
integer |
<optional> |
600 | The bottom bound of the world. |
setBounds(widthopt, heightopt)
Sets the size (bounds) of the camera.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
width |
integer |
<optional> |
800 | The width of the camera. |
height |
integer |
<optional> |
600 | The height of the camera. |
setBoundsToCamera()
Sets the size (bounds) of the game world to the size of the camera.
setBoundsToGame()
Sets the size (bounds) of the game world to size of the game container.