Quickstart¶
Here is a small example you can use to get a feel for the engine.
Minimal moving entity example¶
from arepy import ArepyEngine, Renderer2D, SystemPipeline
from arepy.bundle.components import RigidBody2D, Transform
from arepy.ecs import Entities, Query, With
from arepy.math import Vec2
def movement_system(
query: Query[Entities, With[Transform, RigidBody2D]],
renderer: Renderer2D,
) -> None:
delta_time = renderer.get_delta_time()
for transform, rigidbody in query.iter_components(Transform, RigidBody2D):
transform.position.x += rigidbody.velocity.x * delta_time
transform.position.y += rigidbody.velocity.y * delta_time
engine = ArepyEngine(title="Quickstart")
world = engine.create_world("main")
(
world.create_entity()
.with_component(Transform(position=Vec2(32, 32)))
.with_component(RigidBody2D(velocity=Vec2(60, 20)))
.build()
)
world.add_system(SystemPipeline.UPDATE, movement_system)
engine.set_current_world("main")
engine.run()
What happens here¶
ArepyEngineinitializes the windowing, rendering, audio, and resource layercreate_world()creates aWorldbacked by a fresh ECSRegistryworld.create_entity()returns anEntityBuilderwith_component(...)queues components untilbuild()inserts them into the registryworld.add_system(...)registers a callable under a pipeline such asUPDATEQuery[...]arguments are inspected when the system is registered, so matching entities are tracked automatically
Next steps¶
- Learn the exact frame order in Engine Lifecycle
- Learn query filters in Queries
- See ready-to-use components in Built-in Bundle