Snake Game with React Native Skia
Tuesday, October 22, 2024
Try the live demo
Scan to try on your device
Need the app?
demos
snake
An ongoing collection of React Native animations crafted with Reanimated, Gesture Handler, and Skia.
TypeScript
3.2k
296
A classic snake game implementation with smooth animations and score tracking.
What's This About?
This component creates an interactive snake game with animated scoring and game over states. It features a responsive game board that adapts to the screen size, an animated score counter, and a restart mechanism. The implementation includes smooth animations for the snake movement and game state transitions, making it an engaging gaming experience.
Technical Implementation
The component uses:
Game board management
Score animation
Game state handling
Responsive sizing
Touch controls
Usage
// Basic usage
<Snake />
// Game board setup
<SnakeBoard
n={10}
boardSize={boardSize}
ref={snakeGameRef}
onScoreChange={(newScore) => {
score.value = newScore;
}}
onGameOver={() => {
isGameOver.value = true;
}}
/>
// Animated score counter
<AnimatedCount
count={score}
maxDigits={3}
fontSize={24}
textDigitHeight={30}
textDigitWidth={19}
/>
// Game controls
const snakeGameRef = useRef<SnakeBoardRef>(null);
// Restart game
snakeGameRef.current?.restart();
// Board size calculation
const { width: windowWidth } = useWindowDimensions();
const boardSize = Math.floor((windowWidth * 0.7) / 10) * 10;
Unlock the beauty of React Native animations
Learn Reanimated, Gesture Handler & Skia with Reanimate.dev
Feedback on Snake
Ideas, bugs, or anything that felt off: I read every message. For anything else, write to hello@reactiive.io.
Send feedback