Convert Figma logo to code with AI

phaserjs logophaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.

36,911
7,080
36,911
40

Top Related Projects

36,911

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.

43,513

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.

5,851

a fresh, modern & lightweight HTML5 game engine

Cocos2d for Web Browsers. Built using JavaScript.

3,409

JavaScript Game Engine

1,403

Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.

Quick Overview

Phaser is a fast, free, and fun open-source HTML5 game framework. It uses both a Canvas and WebGL renderer internally and can automatically swap between them based on browser support. This allows for fast rendering across desktop and mobile browsers.

Pros

  • Easy to learn and use, with extensive documentation and examples
  • Active community and regular updates
  • Supports both Canvas and WebGL rendering
  • Cross-platform compatibility for desktop and mobile browsers

Cons

  • Limited 3D capabilities compared to some other game engines
  • Performance can be an issue with complex games or large numbers of objects
  • Steeper learning curve for developers new to game development concepts

Code Examples

  1. Creating a simple game scene:
class GameScene extends Phaser.Scene {
    constructor() {
        super('GameScene');
    }

    preload() {
        this.load.image('logo', 'assets/logo.png');
    }

    create() {
        this.add.image(400, 300, 'logo');
    }
}
  1. Adding physics to a sprite:
create() {
    this.player = this.physics.add.sprite(100, 450, 'player');
    this.player.setBounce(0.2);
    this.player.setCollideWorldBounds(true);
}
  1. Handling user input:
create() {
    this.cursors = this.input.keyboard.createCursorKeys();
}

update() {
    if (this.cursors.left.isDown) {
        this.player.setVelocityX(-160);
    } else if (this.cursors.right.isDown) {
        this.player.setVelocityX(160);
    } else {
        this.player.setVelocityX(0);
    }

    if (this.cursors.up.isDown && this.player.body.touching.down) {
        this.player.setVelocityY(-330);
    }
}

Getting Started

To start using Phaser, include the library in your HTML file:

<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.min.js"></script>

Then, create a basic game configuration:

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

const game = new Phaser.Game(config);

function preload() {
    // Load assets here
}

function create() {
    // Set up your game objects here
}

function update() {
    // Game loop logic here
}

This setup creates a basic Phaser game with a single scene. You can now start adding game objects, implementing game logic, and creating your game within these functions.

Competitor Comparisons

36,911

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.

Pros of Phaser

  • More mature and stable project with a larger community
  • Extensive documentation and tutorials available
  • Wider range of features and plugins

Cons of Phaser

  • Larger file size, which may impact load times
  • Steeper learning curve for beginners
  • May include unnecessary features for simpler projects

Code Comparison

Phaser (v3):

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    scene: {
        create: create
    }
};

const game = new Phaser.Game(config);

function create() {
    this.add.text(400, 300, 'Hello World', { fontSize: '32px' }).setOrigin(0.5);
}

Phaser CE (v2):

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { create: create });

function create() {
    var text = game.add.text(game.world.centerX, game.world.centerY, 'Hello World', { fontSize: '32px' });
    text.anchor.setTo(0.5, 0.5);
}

The main differences in the code examples are the configuration setup and the way game objects are created and positioned. Phaser v3 uses a more modular approach with scenes, while Phaser CE (v2) uses a more straightforward global game object.

43,513

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.

Pros of PixiJS

  • Lighter weight and faster rendering performance
  • More flexible and customizable for advanced graphics manipulation
  • Better suited for complex animations and interactive visualizations

Cons of PixiJS

  • Steeper learning curve for beginners
  • Less built-in game-specific features and utilities
  • Requires more manual setup for game development

Code Comparison

PixiJS (basic setup):

const app = new PIXI.Application({ width: 800, height: 600 });
document.body.appendChild(app.view);
const sprite = PIXI.Sprite.from('image.png');
app.stage.addChild(sprite);

Phaser (basic setup):

const config = { width: 800, height: 600, scene: { preload, create } };
const game = new Phaser.Game(config);
function preload() { this.load.image('sprite', 'image.png'); }
function create() { this.add.image(400, 300, 'sprite'); }

PixiJS is a powerful rendering engine focused on 2D graphics, while Phaser is a complete game framework built on top of PixiJS. PixiJS offers more flexibility for custom graphics applications but requires more setup for game development. Phaser provides a more comprehensive toolkit for game creation out of the box, making it easier for beginners to get started with game development.

5,851

a fresh, modern & lightweight HTML5 game engine

Pros of melonJS

  • Lighter weight and more minimalistic, potentially better for simpler games
  • Built-in physics engine optimized for platformers
  • Easier learning curve for beginners

Cons of melonJS

  • Smaller community and ecosystem compared to Phaser
  • Less frequent updates and maintenance
  • Fewer advanced features and plugins available

Code Comparison

melonJS:

me.game.onload = function() {
    me.state.set(me.state.PLAY, new PlayScreen());
    me.state.change(me.state.PLAY);
};

Phaser:

const config = { scene: PlayScene };
const game = new Phaser.Game(config);

class PlayScene extends Phaser.Scene {
    create() { /* game logic */ }
}

Summary

melonJS is a lightweight HTML5 game engine that excels in simplicity and ease of use, particularly for platformer games. It offers a built-in physics engine and a gentler learning curve for beginners. However, it has a smaller community and fewer advanced features compared to Phaser.

Phaser, on the other hand, is a more robust and feature-rich game framework with a larger ecosystem and more frequent updates. It provides more advanced capabilities and a wider range of plugins, but may have a steeper learning curve for newcomers.

The choice between the two depends on the project's complexity, desired features, and the developer's experience level.

Cocos2d for Web Browsers. Built using JavaScript.

Pros of cocos2d-html5

  • More comprehensive framework with a wider range of features for game development
  • Better suited for complex, large-scale game projects
  • Stronger support for cross-platform development, including mobile platforms

Cons of cocos2d-html5

  • Steeper learning curve compared to Phaser
  • Less active community and fewer updates in recent years
  • More complex setup and configuration process

Code Comparison

Phaser (creating a simple sprite):

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameDiv');
var sprite = game.add.sprite(400, 300, 'playerSprite');

cocos2d-html5 (creating a simple sprite):

var layer = new cc.Layer();
var sprite = new cc.Sprite("player.png");
sprite.setPosition(400, 300);
layer.addChild(sprite);

Both frameworks offer straightforward ways to create and position sprites, but Phaser's syntax is generally more concise and intuitive for beginners. cocos2d-html5 provides more granular control over the game structure, which can be beneficial for complex projects but may require more setup code.

3,409

JavaScript Game Engine

Pros of Crafty

  • Lightweight and modular architecture, allowing for easier customization
  • Entity-Component-System (ECS) design, which can be more flexible for complex game structures
  • Simpler learning curve for developers familiar with traditional object-oriented programming

Cons of Crafty

  • Smaller community and fewer resources compared to Phaser
  • Less frequent updates and potentially slower bug fixes
  • Limited built-in features, requiring more manual implementation for advanced game mechanics

Code Comparison

Crafty:

Crafty.e('2D, DOM, Color')
  .attr({x: 0, y: 0, w: 100, h: 100})
  .color('#FF0000');

Phaser:

this.add.rectangle(0, 0, 100, 100, 0xFF0000);

Both examples create a red rectangle, but Crafty uses its entity-component system, while Phaser uses a more straightforward method call. Crafty's approach allows for more modular and extensible game objects, while Phaser's syntax is more concise and immediately understandable for simple shapes.

1,403

Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.

Pros of Kiwi.js

  • Smaller file size and potentially faster load times
  • More modular architecture, allowing for easier customization
  • Better suited for simpler 2D games and prototypes

Cons of Kiwi.js

  • Less active development and smaller community compared to Phaser
  • Fewer features and plugins available out-of-the-box
  • Limited documentation and learning resources

Code Comparison

Kiwi.js:

var game = new Kiwi.Game('content', 'MyGame', state, { renderer: Kiwi.RENDERER_WEBGL });
var state = new Kiwi.State('MyState');
state.create = function () {
    this.sprite = new Kiwi.GameObjects.Sprite(this, this.textures.sprite, 100, 100);
    this.addChild(this.sprite);
};

Phaser:

var config = { type: Phaser.AUTO, width: 800, height: 600, scene: { create: create } };
var game = new Phaser.Game(config);
function create() {
    this.add.sprite(100, 100, 'sprite');
}

Both frameworks offer similar functionality for creating 2D games, but Phaser has a more extensive feature set and larger community support. Kiwi.js may be preferable for smaller projects or developers seeking a more lightweight solution.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Phaser - HTML5 Game Framework

Phaser Banner

Discord JSDelivr GitHub

Phaser is a fast, free, and fun open source HTML5 game framework that offers WebGL and Canvas rendering across desktop and mobile web browsers and has been actively developed for over 10 years.

Games can be built for the web, or as YouTube Playables, Discord Activies, Twitch Overlays or compiled to iOS, Android, Steam and native apps using 3rd party tools. You can use JavaScript or TypeScript for development. Phaser supports over 40 different front-end frameworks including React and Vue.

Phaser is commercially developed and maintained by Phaser Studio Inc along with our fantastic open source community. As a result of rapid support, and a developer friendly API, Phaser is currently one of the most starred game frameworks on GitHub.

Interested in learning more? Click the image below to watch our intro video.

YouTube

Create Phaser Game App

The easiest way to get started quickly with Phaser is our create-phaser-game app. This CLI tool presents an interactive selection of official project templates and demo games. Issue the command, answer some questions and the app will download and configure the right package for you.

npm create @phaserjs/game@latest
npx @phaserjs/create-game@latest
yarn create @phaserjs/game
pnpm create @phaserjs/game@latest
bun create @phaserjs/game@latest

We support all of the following frameworks and bundlers:

FrameworksBundlers
Vue.jsVite
ReactRollup
AngularParcel
Next.jsWebpack
SolidJSESBuild
SvelteImport Map
RemixBun

Most come in both JavaScript and TypeScript versions.

View the create game app tutorial.

Installing Phaser from NPM

Install via npm:

npm install phaser

Using Phaser from a CDN

Phaser is on jsDelivr which is a "super-fast CDN for developers". Include either of the following in your html:

<script src="//cdn.jsdelivr.net/npm/phaser@3.85.0/dist/phaser.js"></script>
<script src="//cdn.jsdelivr.net/npm/phaser@3.85.0/dist/phaser.min.js"></script>

It is also available from Cloudflare's cdnjs:

<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.85.0/phaser.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.85.0/phaser.min.js"></script>

Phaser TypeScript Definitions

Full TypeScript definitions can be found inside the types folder. They are also referenced in the types entry in package.json, meaning modern editors such as VSCode will detect them automatically.

Depending on your project, you may need to add the following to your tsconfig.json file:

"lib": ["es6", "dom", "dom.iterable", "scripthost"],
"typeRoots": ["./node_modules/phaser/types"],
"types": ["Phaser"]

API Documentation

Read our full API Documentation at https://newdocs.phaser.io/. Use the links at the top of the page to navigate the namespaces, classes, events and Game Objects and also to use the search box.

We maintain documentation for the 10 most recent versions on this site.

Getting Started with Phaser

We recommend the following to begin your journey:

New tutorials are being published every week, so check our site for more.

Phaser by Example Book

We have published a brand-new free 500 page book on game development with Phaser. Learn by building shoot-em-ups, puzzle games, rogue-likes and more.

Phaser by Example

Written by long-time prolific Phaser enthusiast Pello Xabier Altadill and Richard Davey, creator of Phaser, it features up-to-date content on building games with Phaser v3.85.

Work through the process of creating a variety of games, allowing you to learn from real-life examples. The games start simple, with an infinite runner game, and then progresses to building a shoot-em-up, a platformer, a puzzle game, a rogue-like, a story game and even 3D and multiplayer games.

It also contains a large section on the core concepts of Phaser, covering the terminology and conventions used by the framework, as well as a comprehensive deep dive into Game Objects.

Register for a free Phaser account to download the book.

Source Code Examples

We have created hundreds of examples and they are all available with full source code and assets.

Browse the examples on the Phaser 3 Labs

Phaser 3 Plugins

Super community member RexRainbow has been publishing Phaser content for years, compiling an impressive catalogue of plugins that all Phaser developers should be aware of.

You'll find Phaser Plugins that extend the framework with features such as UI controls, text input boxes, Firebase support, Finite State Machines and lots more. His set of Phaser Notes are also invaluable reading.

Phaser Sandbox

The Phaser Sandbox is a fully-configured online editor, ready to go direct in your desktop browser. It's loaded with all the core versions of Phaser and packed full of handy features. Register for a free Phaser account to create and save your own sandbox entries. Or view one just like this.

Phaser Compressor

Use our powerful new web-based tool to crunch your Phaser bundles down by up to 60%, enabling only the features your game requires.

Read more about Phaser Compressor

Change Log

We meticulously keep track of new features, updates and bug fixes in our change logs. Each version of Phaser has its own change log:

Have fun!

Grab the source and join the fun!

Phaser wouldn't have been possible without the fantastic support of the community. Thank you to everyone who supports our work, who shares our belief in the future of HTML5 gaming, and Phaser's role in that.

Happy coding everyone!

Cheers,

Rich and the whole team at Phaser Studio

boogie

Visit the Phaser website
Play some amazing games
Learn By browsing our API Docs, Support Forum and StackOverflow
Code Examples? We've over 2000 Examples to learn from
Read the weekly Phaser World Newsletter
Be Social: Join us on Discord and Reddit or follow us on Twitter

Powered by coffee, anime, pixels and love.

The Phaser logo and characters are © 2011 - 2024 Phaser Studio Inc.

All rights reserved.

"Above all, video games are meant to be just one thing: fun. Fun for everyone." - Satoru Iwata

NPM DownloadsLast 30 Days