Phaser Virtual Joystick - Default
Basic example showing the default behavior of the Virtual Joystick component.
Default Virtual Joystick
Basic example showing the default behavior of the Virtual Joystick component. Perfect for mobile game controls and touch-based interactions.
Features
- đšī¸ Touch Controls: Intuitive touch-based joystick controls
- đą Mobile Optimized: Designed specifically for mobile devices
- đ¯ Precise Input: High-precision analog movement input
- đ¨ Customizable: Fully customizable appearance and behavior
- ⥠Performance: Optimized for 60fps gameplay
Live Example
Loading game...
Usage Example
import { VirtualJoystick } from 'phaser-virtual-joystick';
class GameScene extends Phaser.Scene {
private joystick?: VirtualJoystick;
private character?: Phaser.GameObjects.Arc;
create() {
// Create a virtual joystick with default settings
this.joystick = new VirtualJoystick({
scene: this,
bounds: {
topLeft: { x: 0, y: 40 },
bottomRight: { x: this.cameras.main.width / 2, y: this.cameras.main.height },
},
stickIcon: this.add.text(0, 0, 'đŽ', {
fontSize: '24px',
color: '#ffffff'
}),
enableWithoutTouch: true,
});
// Listen to joystick events
this.joystick.on('move', (data) => {
console.log(`Joystick position: ${data.x}, ${data.y}`);
// Move character based on joystick input
if (this.character) {
this.character.x += data.x * 2;
this.character.y += data.y * 2;
}
});
this.joystick.on('press', () => {
console.log('Joystick pressed');
});
this.joystick.on('release', () => {
console.log('Joystick released');
});
}
update() {
this.joystick?.update();
}
} Configuration Options
Basic Options
- âĸ
scene- Phaser scene instance - âĸ
bounds- Touch area boundaries - âĸ
stickIcon- Custom joystick icon - âĸ
enableWithoutTouch- Enable on non-touch devices
Events
- âĸ
move- Joystick movement - âĸ
press- Joystick pressed - âĸ
release- Joystick released - âĸ
update- Called every frame
đą Mobile Device Required
This demo works best on touch devices. If you're on a desktop, try using your browser's device emulation mode to see the joystick in action.
Instructions:
- Touch and drag in the left half of the screen to use the joystick
- Watch the character move based on joystick input
- Position and status are displayed in real-time