API Reference
The practical index. Every entry says what it does and how to use it in one sentence, grouped by purpose rather than alphabetically. The deeper theory lives on the guide pages; an entry links to its guide when one exists.
MAP DATA & LOADING
Loading
load_map(path) → TilemapData
Entry point for a tilemap-editor map JSON. Feeds TileLayerRenderer and PhysicsWorld.from_map. Exposes tile_size, render_scale, parsed and build_tile_map(). Full wiring on the Map Parsing & Rendering page.
parse_map_dict / parse_map_file / parse_map_json
Lower-level parsers behind load_map. parse_map_json handles a JSON string;
parse_map_file a path.
TilemapData.build_tile_map(exclude_layers=None, use_gids=False) → dict
Collapses the map's tile layers into { (col, row): tile_id } , the layer the runner iterates and PhysicsWorld owns. use_gids=True keys by global tile id.
TilemapData.get_tile_surface(ttype, variant, copy_surface=True) → Surface | None
Gets one tile texture from the tileset, scaled by render_scale. Handy when you want a tile's art outside the renderer (icons, minimaps).
Parsed data classes
ParsedMap / ParsedMeta / ParsedLayer / ParsedObject / ParsedObjectArea / ParsedTile / ParsedTileset / ParsedAutotileGroup / ParsedAutotileRule / ParsedProjectState / TilesetAnimation / ObjectAnimation
Read-only data classes for everything a map JSON contains. You usually touch parsed.meta.tile_size and parsed.tilesets; the rest is there when you need to query editor data. ParsedLayer now carries image_path / image_rect for type == "image" (aliases "background", "background_layer"). ParsedObject.animation is ObjectAnimation | None — required frame_count + frame_duration_ms, optional speed, loop, animation_mode, random_phase, frames; bad values raise MapParseError.
BackgroundLayer / TilemapData.background_layer
Eagerly loaded image layer: image_path, image_rect: (x,y,w,h) | None, surface: Surface | None. Exposed as TilemapData.background_layer (first image layer). get_layers(layer_type="image") lists all.
TilemapData.get_object_animation(obj, render_scale=1.0) → AnimData | None
Returns the effective object animation as AnimData (a normalized dict with frames as surfaces, frame_w/h, frame_duration_ms, loop, animation_mode, and properties). When per-object obj.animation is None, falls back to the matching tileset animation; returns None only when neither the object nor its tileset defines an animation. The render_scale parameter scales both the frame surfaces and their dimensions in the returned dict (default 1.0 leaves at source resolution). Access frames via anim_data["frames"]. Playback (speed, loop, random_start_times hash) is user-side.
Nodes, TMX, objects
parse_nodes_dict / parse_nodes_file / ParsedNode / AreaNode
Parses editor node data (e.g. particle emitters placed in the map). AreaNode wraps a parsed node with itsrect and properties, scaled by render_scale; see JSON Formats for a real example.
parse_tmx_file / parse_tsx_file / TmxParseError
Tiled TMX/TSX converter: bridge maps made in Tiled into the same parsed structures.
load_map_objects / MapObject
MapObject is the body used by polygon solids: it keeps its own shapes instead of relying on Body, which only accepts primitives. Use this one for polygon bodies.
SHAPES & COLLISION DATA
Primitive shapes
RectangleShape(width, height, offset=(0,0))
Box. (x, y) anchor is top-left plus offset. Only primitive shapes are accepted on Body.
CircleShape(radius, offset=(0,0))
Disc. (x, y) anchor is the center plus offset.
CapsuleShape(radius, height, offset=(0,0))
Vertical capsule: two circles height apart. Full collision against every shape type.
CollisionPolygon(vertices, one_way=False)
Tile/object polygon. transform(tile_x, tile_y, scale) moves it to world space; is_valid() requires ≥ 3 vertices. one_way=True = platform pass-through from below (honored by the platformer family).
Collision containers
TilesetCollision(tileset_name, tile_size, tiles)
Per-tile-id polygons. has_collision(tile_id), get_world_shapes(tile_id, x, y, scale), and merge(collisions, firstgids) for multi-tileset maps.
TileCollisionData(tile_id, shapes)
One tile's polygons; has_collision().
CharacterCollision(name, shape, properties, collision_layer, collision_mask)
A sprite's single shape, authored in the editor. Feed it to your sprite at spawn.
ObjectCollisionData / ObjectCollisionRegionData
Region-based polygon paint. get_region(id), per-region layer/mask.
CollisionCache
Loads and caches collision JSON: get_tileset_collision(path), get_character_collision, get_object_collision; clear_collision_cache() to drop it. Also the module-level load_* and parse_*_collision functions.
MOVEMENT: COLLISIONRUNNER
Full treatment on the CollisionRunner guide. Here's the surface:
Construction
from_game_type(game_type, tile_size=(32,32), strict=False, render_scale=1.0)
'platformer' | 'topdown' | 'rpg' presets; see the guide's table. Unknown names raise ValueError.
from_world(world, game_type='platformer', strict=False)
Preset + attach in one call. The world's tile_size/render_scale are adopted.
attach(world) / detach()
Bind or unbind a PhysicsWorld. Attach once; pass None, None for tile args afterwards.
Movement
move_and_slide(sprite, tileset, tiles, delta_x, delta_y, slope_slide=False, world=None)
Displacement + wall sliding. No gravity, never reads vx/vy. Fast path tries the full move first.
move_rpg(sprite, tileset, tiles, delta_x, delta_y, world=None)
Displacement + full blocking. No sliding: a diagonal into a corner stops both axes.
move_grounded(sprite, tileset, tiles, dt, velocity=None, world=None)
Gravity + landing. velocity=(vx, vy) skips gravity. Ledge detection when the sprite was grounded.
move_platformer(sprite, tileset, tiles, dt, input_x=0.0, jump_pressed=False, velocity=None, world=None)
Gravity, jump, step-up, one-way platforms, ground snapping.
move_platformer_with_slide(...) → same shape
Slope-aware: walks polygon floor surfaces within max_walk_angle.
move(sprite, tileset, tiles, delta_x, delta_y, dt, **kwargs)
Dispatches on self.mode (SLIDE/PLATFORMER/RPG/GROUNDED), handy for one generic call.
Queries & config
get_tile_at(world_x, world_y) / get_tile_shapes / get_nearby_tile_shapes
World-space queries without moving anything.
validate_config(strict=None)
Range and consistency checks; called by presets. See the guide's validation section.
CollisionResult
collided, final_x, final_y, hit_wall_x, hit_wall_y, hit_ceiling, on_ground, slide_vector.
MovementMode
Enum: SLIDE, PLATFORMER, RPG, GROUNDED (moves via move_grounded; reachable through the raw CollisionRunner(tile_size, mode=...) constructor, not through the from_game_type presets).
PHYSICS WORLD & BODIES
PhysicsWorld
PhysicsWorld(tile_map, tileset_collision, tile_size=(32,32), render_scale=1.0)
The space. A tile_map without tileset_collision raises ValueError.
from_map(tilemap_data, tileset_collision, *, exclude_layers=None, use_gids=False)
Build from a loaded map; adopts the map's grid geometry.
add_body / remove_body / clear_bodies
Body management. Duplicate add_body is a no-op; removing an absent body raises ValueError.
collides_with_body(sprite) → Body | None
First overlapping body in insertion order, self excluded, layers honored. Bodies are always solid both ways.
__contains__ / __len__
body in world, len(world).
Body
Body(collision_shape, x=0, y=0, *, vx=0, vy=0, mode='static', collision_layer=1, collision_mask=0xFFFFFFFF, game_id='')
A solid. Primitive shapes only (TypeError otherwise); mode in ('static', 'kinematic'): scripted velocity, no engine dynamics. top_y_at(world_x) and as_polygon() back the resolver's ground sampling and slide normals.
Protocols: the sprite contract
ICollidable / ICollidableObject / ICollidableSprite
The duck-type contracts the runner and world accept. ICollidable: x, y, collision_shape. ICollidableObject adds collision_layer/mask. ICollidableSprite adds vx, vy, on_ground for the physics modes. Anything with these attributes works; no subclassing required.
RENDERING & CAMERA
TileLayerRenderer
TileLayerRenderer(data, *, include_hidden_layers=False)
Draws the visible tile layers, chunk-culled (32×32 tiles per chunk). render(target, camera_xy=(0,0), viewport_size=None, *, extra_objects=None, current_time_ms=None) → LayerRenderStats. warm_cache() pre-bakes tile variants (then frees the source data). Respects layer z_index, y_sort and tileset animations.
get_layer_dict() → dict
Raw {layer_id: TileLayer} view of the layers the renderer draws — for debug readouts and custom layer iteration.
LayerRenderStats
drawn_tiles, skipped_tiles, visible_layers: your per-frame culling report.
Camera
Camera(viewport_width, viewport_height, mode='centered')
'centered' keeps the target centered; 'deadzone' only moves when the target exits a box. follow(target) (needs x, y, collision_shape), update(dt), offset, shake(duration, intensity), lerp_speed, bounds.
ANIMATION
AnimationPlayer
SpriteAnimationSet.load(json_path, *, spritesheet_path=None, extra_search_base=None, render_scale=1.0)
Loads an animation JSON + spritesheet into one object. render_scale scales the spritesheet and its atlas grid (tile_size, grid_offset) so frames render at a different resolution; values must be finite and > 0, and scales that produce zero-sized or non-fitting cells raise ValueError. get_image(variant_id), get_content_bounds(clip_name).
AnimationPlayer(animation_set, animation_name)
Frame clock: update(dt_ms), get_current_image(), reset(), finished, frame_index. Honors per-frame durations and loop.
AnimationClip / AnimationFrame / AnimationLibrary / AnimationMarker + parse_animation_dict / parse_animation_file / parse_animation_json
Parsed animation data. AnimationParseError for bad files.
PARTICLES
Fields & systems
ParticleField(area, *, profile=None, shape='fog', color=(200,205,215), alpha=14, global_alpha=1.0, density=1.0, direction=0 | 'random', speed=(6,14), size=(70,120), spread=30, layers=1, quality='medium'|'low'|'high', ground_bias=True, render_scale=1.0, blend=0) / FOG_PROFILE
High-level continuous field helper. Builds wrapped fields internally, so users tune density, strength (global_alpha), color, motion and quality instead of particle internals. Layer tuning comes from a FieldProfile — plain data, e.g. the shipped FOG_PROFILE, which you can copy and tweak for your own moods. Profiles are immutable; FOG_PROFILE.with_alpha(factor, name=None) returns a scaled copy without touching the source. blend passes a pygame blend flag (e.g. pygame.BLEND_RGBA_ADD for additive particles, pygame.BLEND_PREMULTIPLIED for premultiplied tints); for scene glow, alpha-blend the field into a black RGB buffer and blit that with pygame.BLEND_RGB_ADD. Every parameter, its valid values and its meaning: the Particles parameter reference.
ParticleSystemConfig(particle_shape, spawn_rate, max_particles, lifetime_min/max, speed_min/max, direction, spread, start_color_r/g/b/a, end_color_r/g/b/a, alpha_fade, gravity_x, gravity_y)
Low-level particle config and advanced escape hatch. Full wiring on the Particles page.
ParticleSystem(config) + ParticleRenderer / SpriteBatchRenderer / ParticleEmitter / ParticleEmitterNode
The runtime: emitters spawn, fade, and batch-draw. Node-based emitters come from the map's node data (see JSON Formats). clear_texture_caches() frees loaded textures.
parse_particle_dict / parse_particle_file / PARTICLE_SHAPES / EMISSION_SHAPES / ALPHA_FADE_MODES
Parse configs from JSON and the accepted value sets.
NAVIGATION
Pathfinding
NavGrid / Pathfinder / PathFollower
NavGrid builds the walkable grid from a tile layer; Pathfinder computes a path; PathFollower moves an entity along it. Full wiring on the Pathfinding page and in examples/rpg-pathfinding/main.py.
NavGrid.is_one_way(tx, ty) → bool
True if the tile at (tx, ty) carries a one-way polygon. The pathfinding answer to "can I stand on it" — one-way tiles are walkable, solid tiles are walls.
UTILITIES & QUERIES
Detection
check_collision(a, b) → CollisionHit | None
Layer filter → AABB broadphase → narrowphase (deepest pair wins). Handles multi-shape objects.
should_collide(a, b)
The mutual-agreement layer rule: (a_mask & b_layer) and (b_mask & a_layer).
aabb_overlap / get_shape_aabb / get_shape_bounds
Box math. get_shape_bounds backs the runner's tile queries.
circle_vs_circle / rect_vs_rect / rect_vs_circle / polygon_vs_polygon / polygon_vs_rect / polygon_vs_circle / rect_vs_tilemap
Standalone narrowphase tests, when you want collision without the runner.
CollisionHit
resolve(), slide_velocity(), involves(), other(): the object-collision lane's results.
ERRORS
Raised by parsers and validators
MapParseError / CollisionParseError / AnimationParseError / TmxParseError
All subclass ValueError. Parse failures give you the offending data plus the reason. The runner raises plain ValueError for config violations and invalid game_type.