Sprites¶
Animated sprite classes for player and NPC characters.
Location¶
AnimatedPlayer¶
Player character sprite with 4-directional animation.
Constructor¶
from pedre.sprites import AnimatedPlayer
player = AnimatedPlayer(
sprite_sheet_path="characters/player.png",
tile_size=32,
scale=2.0,
center_x=320,
center_y=240,
# Idle animations
idle_up_frames=4, idle_up_row=0,
idle_down_frames=4, idle_down_row=1,
idle_left_frames=4, idle_left_row=2,
idle_right_frames=4, idle_right_row=3,
# Walk animations
walk_up_frames=6, walk_up_row=4,
walk_down_frames=6, walk_down_row=5,
walk_left_frames=6, walk_left_row=6,
walk_right_frames=6, walk_right_row=7
)
Parameters:
sprite_sheet_path(str) - Path to sprite sheet image relative to assetstile_size(int) - Size of each sprite frame in pixelsscale(float) - Sprite scale multipliercenter_x(float) - Initial X positioncenter_y(float) - Initial Y positionidle_*_frames(int) - Number of frames for each idle direction animationidle_*_row(int) - Row index in sprite sheet for each idle directionwalk_*_frames(int) - Number of frames for each walk direction animationwalk_*_row(int) - Row index in sprite sheet for each walk direction
Methods¶
update_animation¶
update_animation(delta_time: float, moving: bool = False) -> None
Update sprite animation state.
Parameters:
delta_time(float) - Time elapsed since last updatemoving(bool) - Whether the player is currently moving
Example:
set_direction¶
set_direction(direction: str) -> None
Change facing direction.
Parameters:
direction(str) - One of: "up", "down", "left", "right"
Example:
Sprite Sheet Layout¶
The player sprite sheet should follow this structure:
- 4 directions: Up, Down, Left, Right
- 2 animation states: Idle and walking
- Multiple frames: Variable per direction (typically 4-8 frames)
- Consistent size: All frames must be the same dimensions
Example Sprite Sheet¶
Row 0: Idle Up [frame 0] [frame 1] [frame 2] [frame 3]
Row 1: Idle Down [frame 0] [frame 1] [frame 2] [frame 3]
Row 2: Idle Left [frame 0] [frame 1] [frame 2] [frame 3]
Row 3: Idle Right [frame 0] [frame 1] [frame 2] [frame 3]
Row 4: Walk Up [frame 0] [frame 1] ... [frame 5]
Row 5: Walk Down [frame 0] [frame 1] ... [frame 5]
Row 6: Walk Left [frame 0] [frame 1] ... [frame 5]
Row 7: Walk Right [frame 0] [frame 1] ... [frame 5]
AnimatedNPC¶
Non-player character sprite with animation and AI.
Constructor¶
from pedre.sprites import AnimatedNPC
npc = AnimatedNPC(
name="merchant",
sprite_sheet_path="npc.png",
tile_size=64,
columns=12,
scale=1.0,
# Idle animations
idle_up_frames=4, idle_up_row=0,
idle_down_frames=4, idle_down_row=1,
idle_left_frames=4, idle_left_row=2,
idle_right_frames=4, idle_right_row=3,
# Walk animations
walk_up_frames=6, walk_up_row=4,
walk_down_frames=6, walk_down_row=5,
walk_left_frames=6, walk_left_row=6,
walk_right_frames=6, walk_right_row=7,
# Optional special animations
appear_frames=9, appear_row=8,
interact_down_frames=5, interact_down_row=9
)
Parameters:
name(str) - Unique NPC identifiersprite_sheet_path(str) - Path to sprite sheet relative to assetstile_size(int) - Size of each sprite frame in pixelscolumns(int) - Total number of columns in sprite sheetscale(float) - Sprite scale multiplieridle_*_frames(int) - Frames for idle animations per directionidle_*_row(int) - Row index for idle animations per directionwalk_*_frames(int) - Frames for walk animations per directionwalk_*_row(int) - Row index for walk animations per directionappear_frames(int, optional) - Frames for appear animationappear_row(int, optional) - Row index for appear animationdisappear_frames(int, optional) - Frames for disappear animationdisappear_row(int, optional) - Row index for disappear animationinteract_*_frames(int, optional) - Frames for interact animations per directioninteract_*_row(int, optional) - Row index for interact animations per direction
Auto-Generated Animations¶
- If only
appear_*is defined:disappearis auto-generated by reversing appear frames - If only
disappear_*is defined:appearis auto-generated by reversing disappear frames - If
interact_left_*is not specified butinteract_right_*exists: left is generated by flipping right horizontally
Attributes¶
name: str- Unique NPC identifierdialog_level: int- Current conversation progression level
Example¶
See Also¶
- Player Plugin - PlayerPlugin documentation
- NPC Plugin - NPCPlugin documentation
- Tiled Integration - Setting up sprites in Tiled