- 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.