World

class pypunk.core.World

Updated by Engine, main game container that holds all currently active Entities.

Useful for organization, eg. “Menu”, “Level1”, etc.

Todo

Usage example, etc.

Note

Make sure to call super().__init__() if overriding to ensure World instance is set up correctly.

visible = True

If False, the World will not be rendered.

self.camera = Point()

Point used to modify location entities are drawn at.

begin()

Override this; called when the World is changed, and is set to the currently active world.

end()

Override this; called when the World is changed, and the active world is no longer this.

update()
render()

Executed by the game loop, updates/renders all contained Entities.

Note

If you override these to give your World update/render code, remeber to call super().update() or your Entities will not be updated/rendered.

mouse_x
mouse_y

Read only. X/Y position of the mouse in the World.

add(e)
remove(e)

Adds/removes Entity e to/from the World at the end of the frame. Returns the added/removed Entity.

add_list(entity[, entity [...]])
remove_list(entity[, entity [...]])

Adds/removes passed Entities to/from the World at the end of the frame. If the first argument is a list, it will be used instead.

remove_all()

Removes all Entities from the World at the end of the frame.

Todo

Mask handling.

bring_to_front(e)
send_to_back(e)

Brings/sends the Entity e to the front/back of it’s containing layer. Returns True if successful.

bring_forward(e)
send_backward(e)

Brings/sends the Entity e once position towards the front/back of it’s containing layer. Returns True if successful.

is_at_front(e)
is_at_back(e)

Returns whether the Entity e is at the front/back of it’s layer.

Todo

Collide Functions.

count

Read only. Number of Entities that are in the World.

type_count(t)

Returns the number of Entities of the type t that are in the World.

class_count(c)

Returns the number of Entities of the class c that are in the World.

layer_count(l)

Returns the number of Entities on the layer l.

first

Read only. The first Entity in the World update order.

layers

Read only. Number of Entity layers the World has.

type_first(t)

The first Entity of type t.

class_first(c)

The first Entity of class c.

layer_first(l)
layer_last(l)

The first/last Entity on layer l.

farthest
nearest

Read only. The Entity that will be rendered first/last by the World.

layer_farthest
layer_nearest

Read only. The Entity that will be rendered first/last by the World.

unique_types

Read only. The number of different types that have been added to the World.

get_type(t, into)

Adds all Entities of type t to provided list into.

get_class(c, into)

Adds all Entities of class c to provided list into.

get_layer(l, into)

Adds all Entities on layer l to provided list into.

get_all(into)

Adds all Entities in World to provided list into.

Project Versions

Previous topic

Engine

Next topic

Entity

This Page