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