- Sprites: Visual assets (images) that define how things look
- Resources: Instances of sprites placed in the world with specific positions and properties
- Relationship: One sprite can be used to create many resources (1:N relationship)
Sprite Library โ Resources โ Pages โ Canvas
โ โ โ โ
Visual Assets โ Instances โ Collections โ Rendered View
- Node.js (v14 or higher)
- npm or yarn
# Clone the repository
git clone <repository-url>
cd sprite-canvas
# Install dependencies
npm install
# Start the development server
npm startThe application will open at http://localhost:3000.
src/
โโโ components/ # Reusable UI components
โ โโโ Controls/ # Viewport control buttons
โ โโโ Tabs/ # Page management interface
โ โโโ Units/ # Resource rendering components
โ โโโ Viewport/ # Main canvas area
โโโ hooks/ # Custom React hooks
โ โโโ usePages.js # Page and resource management
โ โโโ useViewport.js # Canvas navigation and interaction
โโโ data/ # Static data and sprite libraries
โ โโโ spritesLibrary.js
โโโ types/ # Type definitions and factory functions
โ โโโ index.js
โโโ pages/ # Main application pages
โโโ CanvasPage.jsx # Primary application interface
- Page Management: Create, switch, rename, and delete pages using the tab interface
- Sprite Selection: Choose sprites from the library in the left sidebar
- Resource Placement: Double-click on the canvas to place resources
- Resource Selection: Single-click resources to view properties
- Resource Deletion: Use Delete key or inspector button to remove resources
- Canvas Navigation: Mouse wheel to zoom, click-and-drag to pan
DeleteorBackspace: Remove selected resourceMouse Wheel: Zoom in/outClick + Drag: Pan canvasDouble-click: Add resource at cursor position
Manages the page system and resource lifecycle:
- Page creation, deletion, and switching
- Resource addition, removal, and updates
- State persistence across page transitions
Handles canvas interaction and navigation:
- Zoom controls (1x to 16x)
- Pan/drag functionality
- Coordinate transformation between world and screen space
Renders individual resource instances:
- Displays sprite at world coordinates
- Handles selection states
- Shows health bars and visual feedback
Main canvas area:
- Renders all resources for current page
- Manages interaction events
- Applies zoom and pan transformations
Page management interface:
- Tab-based page switching
- Inline page renaming
- Resource count indicators
// In src/data/spritesLibrary.js
export const SPRITES_LIBRARY = {
BOAT: createSprite('Boat', '/boat.png'),
TREE: createSprite('Tree', '/tree.png', 64, 128), // Custom dimensions
BUILDING: createSprite('Building', '/building.png'),
};// Custom resource with specialized properties
const customResource = createResource(
'custom_id',
'sprite_tree',
100, 200,
{
type: 'vegetation',
health: 85,
growth_stage: 'mature',
seasonal_variant: 'summer'
}
);Resources support flexible property systems:
const resourceProperties = {
health: 100, // Visual health bar
speed: 1, // Movement capability
type: 'default', // Resource classification
// Custom properties...
inventory: [],
interactions: {},
animations: {}
};User Interaction โ Event Handler โ Hook Action โ State Update โ UI Re-render
โ โ โ โ โ
Double-click โ handleAddResource โ addResource โ setPages โ Canvas Update
The refactoring maintains backward compatibility:
FishResourcecomponent aliased toFishermanResourcecreateFishResourcefunction aliased tocreateResource- CSS classes maintain legacy versions
- Hook methods include both new and old naming
The application uses a dark theme with:
- Primary Color:
#61dafb(cyan blue) - Background:
#282c34(dark gray) - Surfaces:
#1e1e1eand#2a2a2a(darker grays) - Pixelated Rendering: Sprites maintain crisp pixel art appearance
- Efficient Re-renders: React keys and proper dependency management
- Hardware Acceleration: CSS transforms for viewport operations
- Event Optimization: Proper event listener cleanup
- Memory Management: Immutable state updates prevent memory leaks
Potential features for expansion:
- Animation System: Sprite animation sequences
- Layer Management: Z-index and layer organization
- Collision Detection: Resource interaction system
- Import/Export: Save and load canvas configurations
- Multiplayer: Real-time collaborative editing
- Plugin System: Extensible functionality architecture
This project is available under the MIT License.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Creates a sprite definition for the library.
Creates a resource instance from a sprite.
Creates a new canvas page.
Returns page management state and actions.
Returns viewport state and interaction handlers.