DEV Community

loading...
Cover image for Introducing Replay: a cross-platform JS game engine inspired by React

Introducing Replay: a cross-platform JS game engine inspired by React

edbentley profile image Ed Bentley ・1 min read

Today I'm publishing a new open-source library for creating games: Replay.

I've built many indie games over the years (such as The Impossible Game). I've also built many web apps using React.

Replay takes the ideas and concepts that makes React such a great library for building user interfaces, and brings them to game development. Take a look at how Replay manages state and rendering through a declarative API:

const Player = makeSprite({
  init() {
    // Initial state
    return {
      posX: 0,
      posY: 0,
    };
  },

  loop({ state }) {
    // Return new state at 60 fps
    return {
      posX: state.posX + 1,
      posY: state.posY + 1,
    };
  },

  render({ state }) {
    // Draw a circle based on current state
    return [
      t.circle({
        position: {
          x: state.posX,
          y: state.posY,
        },
        color: "#147aff",
        radius: 10,
      }),
    ];
  },
});

Check out the docs on how to quickly get setup with a new JavaScript or TypeScript project, and then deploy to the web or iOS.

I hope you enjoy using it to build some new games!

Discussion (8)

pic
Editor guide
Collapse
matheusligabue profile image
Matheus Ligabue

I've been searching my whole week for something like this!!!! Was studying (and enjoying) Phaser, but was kinda lost on how to organize the code and reason about the game loop. Will definitely check this out!

Collapse
anuraghazra profile image
Anurag Hazra

Nice, any examples/live demos?

Collapse
edbentley profile image
Ed Bentley Author

I’ve got a tutorial with a live demo coming soon, I’ll keep you posted :)

Collapse
edbentley profile image
Ed Bentley Author

There’s now a tutorial here: replay.js.org/tutorial

And list of games here: replay.js.org/games

Collapse
anuraghazra profile image
Anurag Hazra

nice looks awesome thanks!

Collapse
robmeijeren profile image
Rob Meijeren

This is very nice. I am working on a game with a canvas. Am certainly gonna give this a try when it's a bit further down the road. (Wanna see if I can make it myself first 😉)

Collapse
hyliancoder profile image
Collapse
pavermakov profile image
Pavel Ermakov

Yes!!! Thank you!