chamchi0809/r3f-platformer
A 2D platformer game built with React Three Fiber (R3F) and integrated with LDTK (Level Designer Toolkit) for level design and physics using Rapier.
R3F Platformer (WIP)
It's in progress! ๐ง
A 2D platformer game built with React Three Fiber (R3F) and integrated with LDTK (Level Designer Toolkit) for level design and physics using Rapier.
๐ TODO
(LDTK) Add IntGrid Layer Renderer- (LDTK) Add AutoLayer Renderer
- Multiple Levels & Transitions
- Animation System
- Audio System
- Dialogue System
Lighting & Shadows- Particle Effects
- Save/Load System
- Cutscenes
- Power-ups & Items
- Enemy AI (Decision Trees, Navigation)
๐ฎ Features
- React Three Fiber: 3D graphics rendering with React declarative approach
- LDTK Integration: Level design using LDTK editor with custom renderers
- Physics: Realistic physics simulation using Rapier physics engine
- TypeScript: Full TypeScript support for type safety
- Component-based Architecture: Modular and reusable game components
- Entity System: Custom entity rendering system for game objects
- Tile-based Levels: Support for tile-based level design with collision detection
๐ Tech Stack
- React 19 - UI framework
- React Three Fiber - React renderer for Three.js
- React Three Drei - Useful helpers for R3F
- React Three Rapier - Physics integration
- Three.js - 3D graphics library
- LDTK - Level Designer Toolkit integration
- TypeScript - Type-safe development
- Vite - Fast build tool and dev server
- pnpm - Package manager
๐ Project Structure
src/
โโโ Game.tsx # Main game component
โโโ App.tsx # Application entry point
โโโ common/
โ โโโ ldtk/ # LDTK integration modules
โ โโโ components/
โ โ โโโ LdtkMap.tsx # LDTK map renderer
โ โ โโโ layers/ # Layer rendering components
โ โ โโโ tiles/ # Tile rendering components
โ โโโ models/
โ โ โโโ LdtkTypes.ts # LDTK type definitions
โ โโโ utils/ # Utility functions
public/
โโโ assets/
โโโ ldtk/ # LDTK project files and tilesets
๐ ๏ธ Installation
-
Clone the repository
git clone <repository-url> cd r3f-platformer
-
Install dependencies
pnpm install
-
Start development server
pnpm dev
-
Open your browser
Navigate tohttp://localhost:8080
๐ฏ Development
Available Scripts
pnpm dev- Start development serverpnpm build- Build for productionpnpm preview- Preview production build
LDTK Integration
The project includes a custom LDTK integration that allows you to:
- Load LDTK project files (
.ldtk) - Render tiles with collision detection
- Place entities with custom renderers
- Support for multiple layers and levels
Adding New Entities
Define entity renderers in the entityRendererMap:
entityRendererMap={{
"PlayerStart": ({entity, layer, layerPxOffsets, layerPxDimensions}) => {
// Custom entity rendering logic
return <YourEntityComponent />
}
}}Adding New Tiles
Define tile renderers in the tileRendererMap:
tileRendererMap={{
"RECT": (props) => (
<>
<TileSprite {...props}/>
<TileRectCollider {...props}/>
</>
)
}}Physics System
The game uses Rapier physics engine through @react-three/rapier:
- Rigid bodies for physics objects
- Collision detection for tiles and entities
- Debug mode available during development
๐จ Level Design
- Use LDTK Editor to create levels
- Place your
.ldtkfile inpublic/assets/ldtk/ - Configure tile renderers for your tilesets
- Add entity renderers for game objects
๐ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add appropriate types and tests
- Submit a pull request
๐ง Configuration
TypeScript
The project uses multiple TypeScript configurations:
tsconfig.json- Base configurationtsconfig.app.json- Application-specific settingstsconfig.node.json- Node.js build tools
Vite
Custom Vite configuration includes:
- Path aliases (
@points tosrc/) - Development server on port 8080
- React plugin for fast refresh
๐ License
[Add your license here]
๐ค Acknowledgments
- LDTK for the excellent level editor
- React Three Fiber community
- Rapier physics engine