Phaser Hooks - useGame
Access the Phaser game instance and scene management with the useGame hook.
useGame Hook
Access the Phaser game instance and scene management with the useGame hook. This hook provides easy access to game-level functionality and scene management.
Features
- đŽ Game Access: Direct access to the Phaser game instance
- đŦ Scene Management: Easy scene switching and management
- ⥠Performance: Optimized for high-performance games
- đ¯ TypeScript: Full TypeScript support with type safety
Live Example
Loading game...
Usage Example
import { useGame } from 'phaser-hooks';
class GameDemoScene extends Phaser.Scene {
create() {
// Get the game instance
const game = useGame(this);
// Access game properties
console.log('Game width:', game.scale.width);
console.log('Game height:', game.scale.height);
console.log('Current scene:', game.scene.getActiveScene()?.scene.key);
// Scene management
this.input.keyboard?.on('keydown-SPACE', () => {
game.scene.start('next-scene');
});
// Add some interactive elements
this.add.text(this.cameras.main.centerX, 100, 'Press SPACE to switch scenes', {
color: '#ffffff',
align: 'center',
fontSize: '24px',
}).setOrigin(0.5, 0.5);
}
}