All Projects ā†’ FormidableLabs ā†’ React Game Kit

FormidableLabs / React Game Kit

Licence: mit
Component library for making games with React & React Native

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Game Kit

glazejs
A high performance 2D game engine built in Typescript
Stars: āœ­ 96 (-97.86%)
Mutual labels:  tilemap, physics-engine
Micro Racing
šŸš— šŸŽļø šŸŽ® online 3D multiplayer neural networks based racing game
Stars: āœ­ 100 (-97.77%)
Mutual labels:  game, physics-engine
Pixelorama
A free & open-source 2D sprite editor, made with the Godot Engine! Available on Windows, Linux, macOS and the Web!
Stars: āœ­ 2,535 (-43.42%)
Mutual labels:  spritesheet, sprite-animation
Litiengine
LITIENGINE šŸ•¹ The pure 2D java game engine.
Stars: āœ­ 384 (-91.43%)
Mutual labels:  physics-engine, tilemap
Nintendo Switch Eshop
Crawler for Nintendo Switch eShop
Stars: āœ­ 463 (-89.67%)
Mutual labels:  game
Zork
The DUNGEON (Zork I) source
Stars: āœ­ 449 (-89.98%)
Mutual labels:  game
Autobleem
AutoBleem - Alternative to BleemSync/BootMenu, C++ based, GameScanner and Updater for Playstation Classic
Stars: āœ­ 449 (-89.98%)
Mutual labels:  game
Gideros
Gideros Release version
Stars: āœ­ 442 (-90.13%)
Mutual labels:  game
Etlegacy Deprecated
Archived repository. For current repo, see: https://github.com/etlegacy/etlegacy
Stars: āœ­ 470 (-89.51%)
Mutual labels:  game
Lgame
A cross-platform Java game Engine (Framework) , support JavaFX / Android / IOS / HTML5 / Linux / MAC / Windows
Stars: āœ­ 467 (-89.58%)
Mutual labels:  game
Krkrz
Kirikiri Z Project
Stars: āœ­ 460 (-89.73%)
Mutual labels:  game
2048.c
Console version of the game "2048" for GNU/Linux
Stars: āœ­ 453 (-89.89%)
Mutual labels:  game
Lasercrabs
Launch your LASERCRAB at walls, ceilings, and enemy heads in this indie multiplayer shooter where "move" and "attack" are synonymous.
Stars: āœ­ 465 (-89.62%)
Mutual labels:  game
Tprpix
a Cross-Platform, 2D Survival Sandbox Game Project. Based on C++17/cmake/OpenGL/SQLite3.
Stars: āœ­ 448 (-90%)
Mutual labels:  game
Fheroes2
Free implementation of Heroes of Might and Magic II game engine
Stars: āœ­ 471 (-89.49%)
Mutual labels:  game
Railcraft
The Railcraft Mod for Minecraft, source and development.
Stars: āœ­ 446 (-90.04%)
Mutual labels:  game
Dwarfcorp
An open-source 3D colony management game for PC, Mac and Linux
Stars: āœ­ 460 (-89.73%)
Mutual labels:  game
Cgame
äø€äŗ›ē”ØCē¼–写ēš„小ęøøꈏ, 14č”Œč“Ŗåƒč›‡ 22č”Œ2048 22č”Œäæ„ē½—ę–Æę–¹å— 25č”Œę‰«é›·...仄及各ē§å°ēŽ©ę„
Stars: āœ­ 466 (-89.6%)
Mutual labels:  game
Invaders
Invaders game in 512 bytes (boot sector)
Stars: āœ­ 461 (-89.71%)
Mutual labels:  game
Ai2thor
An open-source platform for Visual AI.
Stars: āœ­ 460 (-89.73%)
Mutual labels:  physics-engine

Maintenance Status

react-game-kit

Make games with React & React Native!


Install

npm install react-game-kit --save

Get Started

react-game-kit provides a set of helper components to make it easier to create games with React and React Native.

You'll want to begin by importing the components you need:

import { Loop, Stage } from 'react-game-kit';

Loop & Stage

Next, 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:

render() {
  return (
    <Loop>
      <Stage>
        // Game specific components go here
      </Stage>
    </Loop>
  );
}

The Loop component uses context to pass a subscribable game tick down your component tree. The Stage component does the same with game scale.

World

If you intend on using physics in your game, a good next component would be the World component, which creates and provides a physics engine & world:

render() {
  return (
    <Loop>
      <Stage>
        <World>
          // Game specific components go here
        </World>
      </Stage>
    </Loop>
  );
}

Physics Bodies

Once you have a physics engine/world established, you can use the Body component to define physics bodies inline:

render() {
  return (
    <Loop>
      <Stage>
        <World>
          <Body args={[0,0,75,75]} ref={ (b) => this.body = b.body }>
            // Sprites go here
          </Body>
        </World>
      </Stage>
    </Loop>
  );
}

Using a ref you can obtain a reference to the physics body and modify its properties via the Matter-js API.

Next Steps

Once 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.

React Native

Using this library with React Native is a simple as importing from the native directory:

import { Loop, Stage, ...etc } from 'react-game-kit/native';

Note: AudioPlayer and KeyListener are not implemented on the React Native version.

API

<Loop />

The Loop component acts much like a Redux provider, in that it passes a GameLoop instance down the component tree via this.context.loop.

This 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:

class ChildComponent extends React.Component {
  static contextTypes = {
    loop: PropTypes.object,
  };

  componentDidMount() {
    this.context.loop.subscribe(this.update);
  }

  componentWillUnmount() {
    this.context.loop.unsubscribe(this.update);
  }

  update() {
    // tick logic
  };
}

--

<Stage />

height (number) : Base game height. Defaults to 576.

width (number) : Base game width. Defaults to 1024.

The 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.

--

<World />

gravity (object) : World gravity object.

Defaults:

gravity={{
  x: 0,
  y: 1,
  scale: 0.001,
}}

onCollision (func) : World collision callback.

onInit (func) : World init callback.

onUpdate (func) : World update callback.

The 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.

The onInit callback is a great place to do your initial world setup, things like creating static bodies for walls and the floor.

--

<Body />

args (array) : Initial body creation arguments. Depends on the shape prop, which maps to Matter.Bodies body creation methods detailed here: Matter.Bodies Documentation

All other props on the body component map directly to Matter-js Body properties.

The 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.

--

<Sprite />

offset (array) : Sprite sheet x,y offset.

onPlayStateChanged (func) : Sprite play state changed callback.

repeat (bool) : Determines whether sprite animation should loop.

scale (number) : Scale value for sprite image.

src (string) : src path for sprite sheet.

state (number) : Vertical position in sprite sheet.

steps (array) : Number of animation steps for current row (state).

ticksPerFrame (number) : Number of loop ticks per animation frame.

tileHeight (number) : Height of spritesheet tile.

tileWidth (number) : Width of spritesheet tile.

The 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 & tileWidth props. Next, each animation state is represented by a row, with steps of the animation represented as columns.

--

<TileMap />

columns (number) : number of columns in tile map.

layers (array) : Array of arrays that contain tile indexes.

renderTile (func) : Overrideable tile rendering function.

rows (number) : Number of rows in tile map.

scale (number) : Tile map scale.

src (string) : Tilemap image src path.

tileSize (number) : Tilemap tile size.

width (number) : Tilemap width.

height (number) : Tilemap height.

The 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:

layers={[
  [
    0, 0, 0, 0,
    1, 0, 1, 1,
    0, 0, 1, 0,
    1, 0, 0, 0,
  ]
]}

--

License

MIT License

Maintenance Status

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!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].