Class: World

Carrot.World(game)

Carrot.World

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.
Source:

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.
Source:

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.
Source:
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.
Source:
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.
Source:

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.
Source:

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.
Source:

setBoundsToCamera()

Sets the size (bounds) of the game world to the size of the camera.
Source:

setBoundsToGame()

Sets the size (bounds) of the game world to size of the game container.
Source: