World
class World extends Container
an object representing the physic world, and responsible for managing and updating all childs and physics
Constructor
new World(x: number, y: number, width: number, height: number) → {}
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number |
<optional> |
0 |
position of the container (accessible via the inherited pos.x property) |
y | number |
<optional> |
0 |
position of the container (accessible via the inherited pos.y property) |
width | number |
<optional> |
game.viewport.width |
width of the container |
height | number |
<optional> |
game.viewport.height |
height of the container |
Summary
Properties from World
Application |
|
Set<Body> |
|
QuadTree |
|
Detector |
|
number |
|
Vector2d |
|
string |
|
boolean |
|
Methods from World
World |
|
World |
|
reset the game world |
|
|
|
boolean |
|
Properties inherited from Container
boolean |
|
boolean |
|
Color |
|
boolean |
|
boolean |
|
boolean |
|
string |
|
Properties inherited from Renderable
number |
|
boolean |
|
Container | Entity |
|
ObservableVector2d |
|
boolean |
|
string |
|
Body |
|
Matrix2d |
|
number |
|
boolean |
|
string |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
Rect | RoundRect | Polygon | Line | Ellipse |
|
string |
|
Function |
|
Application |
|
ObservableVector3d |
|
GLShader |
|
Color |
|
boolean |
|
Properties inherited from Rect
Methods inherited from Container
Methods inherited from Renderable
Methods inherited from Rect
Rect |
|
Rect |
|
boolean |
|
Rect |
|
boolean |
|
boolean |
|
boolean |
|
Rect |
|
Rect |
|
Polygon |
|
Rect |
|
Methods inherited from Polygon
Array<number> |
|
boolean |
|
Polygon |
|
Polygon |
|
|
|
Polygon |
|
Polygon |
|
Polygon |
|
Public Properties
broadphase: QuadTree
QuadTree
the instance of the game world quadtree used for broadphase (used by the builtin physic and pointer event implementation)
detector: Detector
Detector
the collision detector instance used by this world instance
fps: number = 60
number
the rate at which the game world is updated, may be greater than or lower than the display fps
physic: string = "builtin"
string
the physic engine used by melonJS
// disable builtin physic
me.game.world.physic = "none";
preRender: boolean = false
boolean
Enabled pre-rendering for all tile layers.
If false layers are rendered dynamically, if true layers are first fully rendered into an offscreen canvas.
the "best" rendering method depends of your game (amount of layer, layer size, amount of tiles per layer, etc.)
Note : rendering method is also configurable per layer by adding a boolean "preRender" property to your layer in Tiled (https://doc.mapeditor.org/en/stable/manual/custom-properties/#adding-properties).
Public Methods
addBody(body: Body) → {World}
Add a physic body to the game world
Name | Type | Description |
---|---|---|
body | Body |
Type | Description |
---|---|
World |
this game world |
removeBody(body: Body) → {World}
Remove a physic body from the game world
Name | Type | Description |
---|---|---|
body | Body |
Type | Description |
---|---|
World |
this game world |
step(dt: number) → {}
update the builtin physic simulation by one step (called by the game world update method)
Name | Type | Description |
---|---|---|
dt | number |
the time passed since the last frame update |
update(dt: number) → {boolean}
update the game world
Name | Type | Description |
---|---|---|
dt | number |
the time passed since the last frame update |
Type | Description |
---|---|
boolean |
true if the world is dirty |