TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why Use React for Game Development?

12 pointsby JSLegendDev7 months ago

4 comments

stevebmark7 months ago
I don&#x27;t agree React is good for game development, and I also am surprised by the title of this blog post compared to what you actually built.<p>To be clear, the entire video is adding a textbox overlay to a <i>non-React</i> game. The actual game is not driven by React at all, it&#x27;s driven by &quot;kaplay&quot; as you can see imported here: <a href="https:&#x2F;&#x2F;github.com&#x2F;JSLegendDev&#x2F;react-kaplay&#x2F;blob&#x2F;5ee7d69ac86d7a2df9bf64bcb346cfedee8dffce&#x2F;src&#x2F;kaplayCtx.js#L1C21-L1C27">https:&#x2F;&#x2F;github.com&#x2F;JSLegendDev&#x2F;react-kaplay&#x2F;blob&#x2F;5ee7d69ac86...</a> and all the sprites and controls are set up independent of React <a href="https:&#x2F;&#x2F;github.com&#x2F;JSLegendDev&#x2F;react-kaplay&#x2F;blob&#x2F;5ee7d69ac86d7a2df9bf64bcb346cfedee8dffce&#x2F;src&#x2F;initGame.js">https:&#x2F;&#x2F;github.com&#x2F;JSLegendDev&#x2F;react-kaplay&#x2F;blob&#x2F;5ee7d69ac86...</a><p>React is very challenging to use with game development, and probably not worth it. This blog post doesn&#x27;t get into the reasons you would actually want to choose React for gamedev, so there&#x27;s nothing to refute. But before you choose React, consider:<p>- React is fundamentally inappropriate for a 60fps game, both because of the need for re-creating immutable data every frame causing a lot more GC, which <i>will</i> slow down your game, and because the component render process is always slower than imperative mutation. So you have to bail out of React, and forego immutability, to get performance. Both react-three-fiber and react-spring sidestep React rendering entirely to get 60fps!<p>- Think about what goes into a game. The content is probably 100% dynamic. Making a React component is easy when you&#x27;re hard coding the contents, or have limited branching (like if the user is logged in). In a game, displaying components is purely dynamic based on state. So you&#x27;ll need one or more components that do something like<p><pre><code> {currentLevelObjects.map(obj =&gt; obj.type === &#x27;player&#x27; ? &lt;Player ... &#x2F;&gt; : obj.type === &#x27;wall&#x27; ? &lt;Wall ... &#x2F;&gt;} </code></pre> and React clearly offers no benefit here. For the record, most react-three-fiber demos are static scenes with hard coded components. If you want an actually fully dynamic game, based on the output of a level editor, you&#x27;re going to be in trouble. And god help you if you need to consider building a level editor as well! Building a level editor and asset pipeline will take up 90% of your efforts, you&#x27;ll build a bad one, and give up eventually.
评论 #41889271 未加载
SeanAnderson7 months ago
I didn&#x27;t find this article especially compelling. It basically says, &quot;Don&#x27;t use React for the game dev specific aspects of development. Instead, use it for the UI since that&#x27;s what React excels at.&quot;<p>I don&#x27;t find that to be especially insightful because there&#x27;s clear parity between a game&#x27;s UI and a website. In contrast, the actual game rendering logic has the potential to ask far more of React than it&#x27;s capable of giving.<p>A couple of years ago I tried building a 2D ant colony sim using React+PixiJS. (<a href="https:&#x2F;&#x2F;github.com&#x2F;MeoMix&#x2F;antfarm">https:&#x2F;&#x2F;github.com&#x2F;MeoMix&#x2F;antfarm</a>) It didn&#x27;t go great because React&#x27;s reconciler became a performance bottleneck very quickly, even with everything memoized, and the GC caused stuttering which was difficult to mitigate when React wants to work with immutable objects rather than mutating existing state. The latter is easy enough to work around, but trying to avoid instantiating strings, etc. just felt like I was working against my tools a bit.<p>That said, new versions of React and PixiJS have come out since I last tried and it&#x27;s possible that those performance enhancements + subdividing my grid and doing smarter updates would allow me to continue on for a while, but, at the time, I didn&#x27;t feel like I was getting the dev experience I wanted out of React for a canvas-driven simulation.<p>All that said, I absolutely find the idea of declarative, reactive game development quite appealing and if your game doesn&#x27;t ask much of performance then the trade-offs for getting that could very well be worth it.
chrisdalke7 months ago
I&#x27;d extend this to suggest vanilla JavaScript, HTML, and CSS is a great choice for recreational game development even if you aren&#x27;t using React:<p>- Extremely forgiving syntax, great for quickly hacking around with concepts<p>- Shareable for effectively free via static sites to any modern device<p>- Live-reloading tools are ubiquitous<p>- HTML&#x2F;CSS provides a significantly better styling &amp; layout framework than any OpenGL UI toolkit
Bellf7 months ago
Truly React is one of the most versatile frontend tools.