r/reactjs•
deppdev

React for idle/incremental game

Hello r/reactjs!

I'm a beginner in React and wanna try to make something up for my holiday project, and got an idea of making an idle/incremental game, like Cookie Clicker. I'm planning to use Redux to store the data and easily spread the data to the components that need it (tracking money and upgrades to 'upgrade shop' container that will receive Redux state as props).

Haven't made it yet, I'm thinking if this would be a good idea, implementing this game with React/Redux, while in most of idle/incremental games, the money gets updated very fast, lets say perhaps every 100ms or even faster (I'm not sure about this). Of course there are other ways to implement this game without having the 100ms timer ticking to update the money count (1s timer instead, or 4s timer for a 4 second 'factory' that user have), but I still want to try on making the update fast enough.

I have encountered an infinite render loop through my learning process, and from my experience it slows down my browser until it become sort of unresponding. I think this game will also share the same problem, by means constantly re-render its components with no sign of stopping, for every 100ms.

The question is, can I actually have a way to build this with React/Redux and get seamless performance, just like other good similar games? Or if it's bad, perhaps there are other libraries or technologies to implement this while still making use of React?

Thanks!

Posted Jan 11, 2019, 3:26 PM UTC

27
teevik_•

I'd think it would be fine, best way is to try

1
deppdevOP•

Will be updating when I have built it, thanks!

1
Demiacle•

While you could make a game in react, i found it super difficult with certain behavior, mainly because you are always going to be limited by the dom. You will also run into rendering limitations for that same reason, so you will have to keep your dom tree as small as possible if you want it snappy.

Also you will want as few components to subscribe to the store as possible especially considering you want updates of fractions of a second. If you run into slow behavior don't be afraid to position absolute visuals since they won't need to recalculate layout.

That being said, an idle game like that is very simple so you should have no problem!

1
deppdevOP•

By "position absolute visual" do you mean the CSS position attribute? Would this helps if the game is only text-based, and probably won't have moving parts in it? It will only toggle over displays regarding to current money value and perhaps display different colors.

Anyway, thanks for your reply and help!

1
Demiacle•

Ya, that only concerns layout with movement. I only mentioned that in case you wanted to implement the particle effects.

1
TheDobbler•

Sounds like a cool projects with a lot of focus on performance.

Just taking a guess but some helpfull ideas could be; to create a queue for changes that executes every sec. Another is being careful with putting everything through redux. I think you can win a lot of performance by putting as such as you can in the normal state.

1
deppdevOP•

Thanks for the reply!

​

a queue for changes that executes every sec

to minimalize the updates needed to the DOM?

​

​

1