Skip to content

QADRAX/react-super-tilemap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—ΊοΈ React Super Tilemap

Build Publish

TypeScript React NPM Storybook

React Super Tilemap is a low-level tilemap rendering engine for React, optimized for browser performance.

Ideal for games and apps that require:

  • Grid-based map rendering.
  • Camera control and zooming.
  • Support for animated, oversized, and offset sprites.
  • Dynamic movable elements.

πŸš€ Installation

npm install react-super-tilemap
# or
yarn add react-super-tilemap

🧱 1. Define your sprites

API Reference: πŸ“œ SpriteDefinition

πŸ”Ή Basic

πŸ•Ή Demo Β· πŸ“„ Code

const sprites: SpriteDefinition[] = [
  {
    key: 'grass',
    imageSrc: ['path/to/grass.png'],
  },
]

πŸ”„ Animated

πŸ•Ή Demo Β· πŸ“„ Code

{
  key: 'ocean',
  imageSrc: [ocean_1, ocean_2, ocean_3, ocean_4],
  animationDelay: 400,
}

⚠️ All animation images must be the same size.

πŸ“ Oversized

πŸ•Ή Demo

{
  key: 'building',
  imageSrc: [building_1],
  animationDelay: 800,
  size: { width: 1, height: 2 },
}

🎯 Offset

πŸ•Ή Demo

{
  key: 'selector',
  imageSrc: [selector1, selector2],
  animationDelay: 800,
  size: { width: 2, height: 2 },
  offset: { col: -0.5, row: 0.5 },
}

πŸ—ΊοΈ 2. Create your tilemap

API Reference: πŸ“œ Tilemap API

πŸ•Ή Demo

<Tilemap tilmapScheme={scheme} spriteDefinition={sprites}>
  ...
</Tilemap>

πŸŽ₯ 3. Add a camera

πŸ”§ ManualCamera

πŸ•Ή Demo

<ManualCamera position={{ col: 0, row: 0 }} zoom={0} />

🧲 ThirdPersonCamera

πŸ•Ή Demo

<ThirdPersonCamera />

🧠 Camera Context

πŸ•Ή Demo

const { addZoomMotion } = useThirdPersonCameraContext()

🧍 4. Add elements

πŸ›  ManualElement

πŸ•Ή Demo

<ManualElement
  elementKey="unit"
  spriteKey="armyIdle"
  layer={1}
  tilePosition={{ x: 0, y: 0 }}
/>

πŸŒ€ MotionableElement

πŸ•Ή Demo

<MotionableElement
  elementKey="unit"
  spriteKey="armyIdle"
  layer={1}
  tilePosition={{ x: 5, y: 5 }}
  motionSettings={{ speed: 1, easing: 'linear' }}
/>

πŸ“š Additional Resources

About

React implementation of a low-level 2D tilemap board optimized for high-performance rendering in web browsers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published