{"id":14963992,"url":"https://github.com/geckosio/phaser-on-nodejs","last_synced_at":"2025-04-04T13:08:29.573Z","repository":{"id":46604475,"uuid":"183928719","full_name":"geckosio/phaser-on-nodejs","owner":"geckosio","description":"Allows you to run Phaser 3 game (including Phaser's physics engines) on Node.js","archived":false,"fork":false,"pushed_at":"2024-12-23T23:37:21.000Z","size":455,"stargazers_count":107,"open_issues_count":5,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T12:06:32.942Z","etag":null,"topics":["node","phaser","physics","server"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geckosio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"yandeu"}},"created_at":"2019-04-28T15:53:45.000Z","updated_at":"2025-03-16T23:05:47.000Z","dependencies_parsed_at":"2024-06-18T16:42:28.700Z","dependency_job_id":"c6173351-66c8-4335-bb2b-e426c455daf1","html_url":"https://github.com/geckosio/phaser-on-nodejs","commit_stats":{"total_commits":88,"total_committers":1,"mean_commits":88.0,"dds":0.0,"last_synced_commit":"8fbe6f98275c89073e9fd50fbb73c9840fc2e14f"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geckosio%2Fphaser-on-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geckosio%2Fphaser-on-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geckosio%2Fphaser-on-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geckosio%2Fphaser-on-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geckosio","download_url":"https://codeload.github.com/geckosio/phaser-on-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182350,"owners_count":20897379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node","phaser","physics","server"],"created_at":"2024-09-24T13:32:26.441Z","updated_at":"2025-04-04T13:08:29.552Z","avatar_url":"https://github.com/geckosio.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n\n\u003ca href=\"https://github.com/yandeu/phaser3-multiplayer-with-physics#readme\"\u003e\n\u003cimg src=\"readme/phaser-on-nodejs.png\" alt=\"logo\" width=\"400\"\u003e\n\u003c/a\u003e\n\n# Phaser on Node.js\n\n### Allows you to run Phaser 3 games (including Phaser's physics engines) on Node.js.\n\n[![Github Workflow](https://img.shields.io/github/actions/workflow/status/geckosio/phaser-on-nodejs/ubuntu.yaml?branch=master\u0026label=github%20build\u0026logo=github\u0026style=flat-square)](https://github.com/geckosio/phaser-on-nodejs/actions?query=workflow%3ACI)\n[![npm](https://img.shields.io/npm/v/@geckos.io/phaser-on-nodejs.svg?style=flat-square)](https://www.npmjs.com/package/@geckos.io/phaser-on-nodejs)\n[![Downloads](https://img.shields.io/npm/dm/@geckos.io/phaser-on-nodejs.svg?style=flat-square)](https://www.npmjs.com/package/@geckos.io/phaser-on-nodejs)\n[![NPM](https://img.shields.io/npm/l/@geckos.io/phaser-on-nodejs.svg?style=flat-square)](LICENSE)\n[![Codecov](https://img.shields.io/codecov/c/github/geckosio/phaser-on-nodejs?logo=codecov\u0026style=flat-square)](https://codecov.io/gh/geckosio/phaser-on-nodejs)\n\n\u003c/div\u003e\n\n## Arcade Physics\n\n⚠️ If your goal is to run the Arcade Physics on the server, I highly recommend using [`arcade-physics`](https://github.com/yandeu/arcade-physics#readme).\n\n## Compatibility\n\nWorks with Phaser \u003e=3.55.2.  \n_Successfully tested with v3.87.0_\n\n## Install\n\n```console\nnpm install @geckos.io/phaser-on-nodejs\n```\n\n## How to use\n\n```js\nrequire('@geckos.io/phaser-on-nodejs')\n// or with es6\nimport '@geckos.io/phaser-on-nodejs'\n```\n\n## Features\n\n- Phaser Physics (Arcade and Matter)\n- Load Images and SpriteSheets\n- Load TileMaps\n- Adjustable Frame Rate\n- Allows to use Multiple Scenes\n\n## Examples\n\n- [Simple Phaser on Node.js example](https://github.com/geckosio/phaser-on-nodejs-example)\n- [Phaser 3 - Multiplayer game example with geckos.io](https://github.com/geckosio/phaser3-multiplayer-game-example#readme)\n- [Phaser 3 - Multiplayer game with physics](https://github.com/yandeu/phaser3-multiplayer-with-physics#readme)\n\n## Basic Setup\n\nInstall and require `phaser` and `@geckos.io/phaser-on-nodejs`. Make sure you use Phaser in headless mode on the server `{ type: Phaser.HEADLESS }`\n\n```js\nrequire('@geckos.io/phaser-on-nodejs')\nconst Phaser = require('phaser')\n\n// set the fps you need\nconst FPS = 30\nglobal.phaserOnNodeFPS = FPS // default is 60\n\n// your MainScene\nclass MainScene extends Phaser.Scene {\n  constructor() {\n    super('MainScene')\n  }\n  create() {\n    console.log('it works!')\n  }\n}\n\n// prepare the config for Phaser\nconst config = {\n  type: Phaser.HEADLESS,\n  width: 1280,\n  height: 720,\n  banner: false,\n  audio: false,\n  scene: [MainScene],\n  fps: {\n    target: FPS\n  },\n  physics: {\n    default: 'arcade',\n    arcade: {\n      gravity: { y: 300 }\n    }\n  }\n}\n\n// start the game\nnew Phaser.Game(config)\n```\n\n## Loading Assets\n\nYou can load textures (images, spritesheets etc.) on the server.\n\n```js\npreload() {\n  // use a relative path\n  this.load.image('star', '../assets/star.png')\n}\n\ncreate() {\n  const star = this.physics.add.sprite(400, 300, 'star')\n}\n```\n\nBut to save some memory, I recommend the following approach instead:\n\n```js\nclass Star extends Phaser.Physics.Arcade.Sprite {\n  constructor(scene, x, y) {\n    // pass empty string for the texture\n    super(scene, x, y, '')\n\n    scene.add.existing(this)\n    scene.physics.add.existing(this)\n\n    // set the width and height of the sprite as the body size\n    this.body.setSize(24, 22)\n  }\n}\n```\n\n## Using node-fetch or axios?\n\nIf you are using **node-fetch**, you do not need to do anything.\n\nIf you are using **axios**, you have to make sure `XMLHttpRequest` will not break:  \n`XMLHttpRequest` is only use in the browser. Phaser.js is a browsers framework which uses `XMLHttpRequest` so phaser-on-nodejs has to provide a mock implementation. Unfortunately, axios is a isomorphic framework. On initialization, axios checks if `XMLHttpRequest` is available and will think it is running in the browser. To make sure axios works on nodejs, we just have to hide `XMLHttpRequest` from axios during its initialization.\nSee the snipped below to make it work:\n\n```js\n// remove fakeXMLHttpRequest\nconst tmp = XMLHttpRequest\nXMLHttpRequest = undefined\n// init axios\nconst axios = require('axios').default\n// restore fakeXMLHttpRequest\nXMLHttpRequest = tmp\n```\n","funding_links":["https://github.com/sponsors/yandeu"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeckosio%2Fphaser-on-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeckosio%2Fphaser-on-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeckosio%2Fphaser-on-nodejs/lists"}