• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

edbentley/replay: A cross-platform JS game engine inspired by React

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

edbentley/replay

开源软件地址:

https://github.com/edbentley/replay

开源编程语言:

TypeScript 74.8%

开源软件介绍:

Replay

Replay is a cross-platform JavaScript game engine inspired by React.

Its declarative API goes against the grain of typical game engines. It's small yet powerful, giving you total control on how your game runs. With a great testing library built in, Replay is ideal for writing bug-free games.

Build your game once and deploy it for web, iOS and Android.

Tutorial · Docs · Blog · Games

⚠️ Status

Replay is still in early development and will go through many breaking changes. However we encourage you to start making games now - your feedback will help shape Replay's future!

Quick Setup

Create a file, copy this in and open it in a browser:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- Load Replay through a CDN -->
  <script src="https://unpkg.com/@replay/[email protected]/umd/replay-core.min.js"></script>
  <script src="https://unpkg.com/@replay/[email protected]/umd/replay-web.min.js"></script>
  <title>Replay Game</title>
</head>
<body>
<script>

// Import from Replay
const { makeSprite, t } = replay;
const { renderCanvas } = replayWeb;

// Setup game size
const gameProps = {
  id: "Game",
  size: {
    landscape: {
      width: 600,
      height: 400,
      maxWidthMargin: 150,
    },
    portrait: {
      width: 400,
      height: 600,
      maxHeightMargin: 150,
    },
  },
  defaultFont: {
    family: "Courier",
    size: 10,
  },
};

// Create a Game Sprite
const Game = makeSprite({
  init() {
    // Our initial state
    return {
      posX: 0,
      posY: 0,
      targetX: 0,
      targetY: 0,
    };
  },

  // This is run 60 times a second. Returns next frame's state.
  loop({ state, getInputs }) {
    const { pointer } = getInputs();
    const { posX, posY } = state;
    let { targetX, targetY } = state;

    // Update our target when the mouse is clicked
    if (pointer.justPressed) {
      targetX = pointer.x;
      targetY = pointer.y;
    }

    return {
      // Update our position to move closer to target over time
      posX: posX + (targetX - posX) / 10,
      posY: posY + (targetY - posY) / 10,
      targetX,
      targetY,
    };
  },

  // Render Textures based on game state
  render({ state }) {
    return [
      t.text({
        color: "red",
        text: "Hello Replay!",
        y: 50,
      }),
      t.circle({
        x: state.posX,
        y: state.posY,
        color: "#147aff",
        radius: 10,
      }),
    ];
  },
});

// Render in the browser using canvas
renderCanvas(Game(gameProps), { dimensions: "scale-up" });

</script>
</body>
</html>



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap