介绍 Replay:一个受 React 启发的跨平台 JS 游戏引擎
今天我发布了一个用于创建游戏的新开源库:Replay。
这些年来,我开发过很多独立游戏(比如《The Impossible Game》)。我也用React开发过很多 Web 应用。
Replay继承了 React 构建用户界面的优秀库的理念和概念,并将其应用于游戏开发。让我们来看看 Replay 如何通过声明式 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,
}),
];
},
});
查看有关如何快速设置新的 JavaScript 或 TypeScript 项目,然后部署到 Web 或 iOS 的文档。
我希望您喜欢使用它来构建一些新游戏!
文章来源:https://dev.to/edbentley/introducing-replay-a-cross-platform-js-game-engine-inspired-by-react-pif