将 GameMaker 加载到 React Native 中

问题描述 投票:0回答:0

我正在开发一个更传统的 React Native 应用程序。已要求在应用程序中包含小型迷你游戏。

我真的很想让我们的开发团队使用游戏制作工具,例如GameMaker。它允许导出 HTML5 资产以将游戏作为 Javascript 运行,所以我想我可以在

WebView
中加载它并完成它。

显然没那么简单:(

我试过以下方法:

  • 导出游戏并将其目录放入 React Native 资产文件夹(例如
    assets/spackrocks/
    )。
  • 安装
    react-native-webview
    包。
  • 在 RN 应用程序的
    Asteroids
    页面内实现游戏:
import { StyleSheet, Platform } from "react-native";
import React from "react";
import { WebView } from "react-native-webview";

const Asteroids = () => {
    const source = Platform.OS === "ios" ? require("../../assets/asteroid/index.html") : { uri: "file:///android_asset/asteroid/index.html" };

    return (
        <WebView
            styles={style.container}
            source={source}
            allowFileAccess={true}
            allowUniversalAccessFromFileURLs={true}
            javaScriptEnabled={true}
            domStorageEnabled={true}
            originWhitelist={["*"]}
            onMessage={event => {
                console.log(event.nativeEvent.data);
            }}
        />
    );
};

export default Asteroids;

const style = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: "#fff",
    },
});

这会毫无问题地加载

index.html
。但是,包含
js
的文件无法在
index.html
中加载。我在控制台中得到以下输出:

Error: 'assets/asteroid/html5game/Space%20Rocks.js' cannot be loaded as its extension is not registered in assetExts

根据我的理解,将“js”附加到

assetsExts
是不可能的,因为js文件不是静态资产,例如图像。


我不确定如何进行。有没有办法做到这一点?我是不是完全错了?

感谢您的帮助:)

reactjs react-native webview game-maker
© www.soinside.com 2019 - 2024. All rights reserved.