{"id":15177736,"url":"https://github.com/formidablelabs/react-game-kit","last_synced_at":"2025-10-01T18:31:01.416Z","repository":{"id":54815355,"uuid":"68275675","full_name":"FormidableLabs/react-game-kit","owner":"FormidableLabs","description":"Component library for making games with React  \u0026 React Native","archived":true,"fork":false,"pushed_at":"2023-01-04T16:18:43.000Z","size":2084,"stargazers_count":4627,"open_issues_count":29,"forks_count":310,"subscribers_count":147,"default_branch":"main","last_synced_at":"2025-01-08T21:43:50.618Z","etag":null,"topics":["component-tree","game","matter","physics-bodies","physics-engine","react","reactjs","sprite-animation","spritesheet","tilemap"],"latest_commit_sha":null,"homepage":"http://reactnext.surge.sh","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/FormidableLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-15T07:46:01.000Z","updated_at":"2025-01-03T21:45:32.000Z","dependencies_parsed_at":"2023-02-02T18:32:44.104Z","dependency_job_id":null,"html_url":"https://github.com/FormidableLabs/react-game-kit","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormidableLabs%2Freact-game-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormidableLabs%2Freact-game-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormidableLabs%2Freact-game-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormidableLabs%2Freact-game-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FormidableLabs","download_url":"https://codeload.github.com/FormidableLabs/react-game-kit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234887394,"owners_count":18902083,"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":["component-tree","game","matter","physics-bodies","physics-engine","react","reactjs","sprite-animation","spritesheet","tilemap"],"created_at":"2024-09-27T14:42:51.419Z","updated_at":"2025-10-01T18:31:00.943Z","avatar_url":"https://github.com/FormidableLabs.png","language":"JavaScript","readme":"\u003ca href=\"https://formidable.com/open-source/\" target=\"_blank\"\u003e\n  \u003cimg alt=\"React Game Kit — Formidable, We build the modern web\" src=\"./react-game-kit-Hero.png\" /\u003e\n\u003c/a\u003e\n\n\u003ch4 align=\"center\"\u003e\n  Make games with React \u0026 React Native!\n\u003c/h4\u003e\n\n***\n\n[![Maintenance Status][maintenance-image]](#maintenance-status)\n\n\u003c!-- MarkdownTOC depth=3 autolink=true bracket=round --\u003e\n\n\n\u003c!-- /MarkdownTOC --\u003e\n\n## Install\n\n`npm install react-game-kit --save`\n\n## Get Started\n\n`react-game-kit` provides a set of helper components to make it easier to create games with React and React Native.\n\nYou'll want to begin by importing the components you need:\n\n```js\nimport { Loop, Stage } from 'react-game-kit';\n```\n\n### Loop \u0026 Stage\n\nNext, in your render method of your top level component, you'll want to put the `Loop` component at the top level, optionally followed by the `Stage` component:\n\n```js\nrender() {\n  return (\n    \u003cLoop\u003e\n      \u003cStage\u003e\n        // Game specific components go here\n      \u003c/Stage\u003e\n    \u003c/Loop\u003e\n  );\n}\n```\n\nThe `Loop` component uses `context` to pass a subscribable game tick down your component tree. The `Stage` component does the same with game scale.\n\n### World\n\nIf you intend on using physics in your game, a good next component would be the `World` component, which creates and provides a physics engine \u0026 world:\n\n```js\nrender() {\n  return (\n    \u003cLoop\u003e\n      \u003cStage\u003e\n        \u003cWorld\u003e\n          // Game specific components go here\n        \u003c/World\u003e\n      \u003c/Stage\u003e\n    \u003c/Loop\u003e\n  );\n}\n```\n\n### Physics Bodies\n\nOnce you have a physics engine/world established, you can use the `Body` component to define physics bodies inline:\n\n```js\nrender() {\n  return (\n    \u003cLoop\u003e\n      \u003cStage\u003e\n        \u003cWorld\u003e\n          \u003cBody args={[0,0,75,75]} ref={ (b) =\u003e this.body = b.body }\u003e\n            // Sprites go here\n          \u003c/Body\u003e\n        \u003c/World\u003e\n      \u003c/Stage\u003e\n    \u003c/Loop\u003e\n  );\n}\n```\n\nUsing a ref you can obtain a reference to the physics body and modify its properties via the [Matter-js API](https://github.com/liabru/matter-js).\n\n### Next Steps\n\nOnce this general structure is established, what follows usually depends on what kind of game you intend to make. Check out the API documentation below for further clarity regarding use of these components.\n\n## React Native\n\nUsing this library with React Native is a simple as importing from the native directory:\n\n```js\nimport { Loop, Stage, ...etc } from 'react-game-kit/native';\n```\n\n\u003e Note: AudioPlayer and KeyListener are not implemented on the React Native version.\n\n## API\n\n#### \\\u003cLoop /\u003e\n\nThe `Loop` component acts much like a Redux provider, in that it passes a GameLoop instance down the component tree via `this.context.loop`.\n\nThis allows you to subscribe and unsubscribe to the main game loop anywhere in your component tree. Here is an example of how this would generally look:\n\n```js\nclass ChildComponent extends React.Component {\n  static contextTypes = {\n    loop: PropTypes.object,\n  };\n\n  componentDidMount() {\n    this.context.loop.subscribe(this.update);\n  }\n\n  componentWillUnmount() {\n    this.context.loop.unsubscribe(this.update);\n  }\n\n  update() {\n    // tick logic\n  };\n}\n\n```\n\n--\n\n#### \\\u003cStage /\u003e\n\n**height** (_number_) : Base game height. Defaults to `576`.\n\n**width** (_number_) : Base game width. Defaults to `1024`.\n\nThe `Stage` component also leverages `context` much like `Loop`, except it passes game scale as `this.context.scale`. You can use this value to appropriately scale positioning and dimension values within your game. Again, you would have to specify `scale: PropTypes.number` in your component's `contextTypes` to receive this value.\n\n--\n\n#### \\\u003cWorld /\u003e\n\n**gravity** (_object_) : World gravity object.\n\nDefaults:\n\n```js\ngravity={{\n  x: 0,\n  y: 1,\n  scale: 0.001,\n}}\n```\n\n**onCollision** (_func_) : World collision callback.\n\n**onInit** (_func_) : World init callback.\n\n**onUpdate** (_func_) : World update callback.\n\nThe `World` component is used as the first step in setting up game physics. It passes a `matter-js` Engine instance down via context as `this.context.engine`. Generally speaking, when getting or settings physics properties you'll want to do this after the physics world is updated in the main tick cycle. You can hook into this using the `onUpdate` prop, or in child components use `Matter.Events.on(this.context.engine, 'afterUpdate', this.update);` to subscribe to the engine updates.\n\nThe `onInit` callback is a great place to do your initial world setup, things like creating static bodies for walls and the floor.\n\n--\n\n#### \\\u003cBody /\u003e\n\n**args** (_array_) : Initial body creation arguments. Depends on the `shape` prop, which maps to Matter.Bodies body creation methods detailed here: [Matter.Bodies Documentation](http://brm.io/matter-js/docs/classes/Bodies.html)\n\nAll other props on the body component map directly to [Matter-js Body properties](http://brm.io/matter-js/docs/classes/Body.html).\n\nThe `Body` component is used to define physics bodies. You will generally want to use `ref` to obtain a reference to the body, at which point you can call Matter-js methods on it, as well as listen to and react to its physic properties in the world update callback.\n\n--\n\n#### \\\u003cSprite /\u003e\n\n\n**offset** (array) : Sprite sheet x,y offset.\n\n**onPlayStateChanged** (func) : Sprite play state changed callback.\n\n**repeat** (bool) : Determines whether sprite animation should loop.\n\n**scale** (number) : Scale value for sprite image.\n\n**src** (string) : src path for sprite sheet.\n\n**state** (number) : Vertical position in sprite sheet.\n\n**steps** (array) : Number of animation steps for current row (state).\n\n**ticksPerFrame** (number) : Number of loop ticks per animation frame.\n\n**tileHeight** (number) : Height of spritesheet tile.\n\n**tileWidth** (number) : Width of spritesheet tile.\n\nThe `Sprite` component lets you define sprite animations using sprite sheets. When creating a sprite sheet, define sprite tile dimensions that will be provided via the `tileHeight` \u0026 `tileWidth` props. Next, each animation state is represented by a row, with steps of the animation represented as columns.\n\n--\n\n#### \\\u003cTileMap /\u003e\n\n**columns** (number) : number of columns in tile map.\n\n**layers** (array) : Array of arrays that contain tile indexes.\n\n**renderTile** (func) : Overrideable tile rendering function.\n\n**rows** (number) : Number of rows in tile map.\n\n**scale** (number) : Tile map scale.\n\n**src** (string) : Tilemap image src path.\n\n**tileSize** (number) : Tilemap tile size.\n\n**width** (number) : Tilemap width.\n\n**height** (number) : Tilemap height.\n\nThe `TileMap` component lets you define tile maps from a tile atlas. Your tilemap is made of up rows and columns. Each layer is then drawn using those numbers as reference. So for example, if you had 4 rows and 4 columns, with 1 layer, your `layers` prop would look like:\n\n```js\nlayers={[\n  [\n    0, 0, 0, 0,\n    1, 0, 1, 1,\n    0, 0, 1, 0,\n    1, 0, 0, 0,\n  ]\n]}\n```\n\n--\n\n\n\n## License\n\n[MIT License](http://opensource.org/licenses/MIT)\n\n## Maintenance Status\n\n**Archived:** This project is no longer maintained by Formidable. We are no longer responding to issues or pull requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!\n\n[maintenance-image]: https://img.shields.io/badge/maintenance-archived-red.svg\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformidablelabs%2Freact-game-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformidablelabs%2Freact-game-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformidablelabs%2Freact-game-kit/lists"}