Hello,
Can it be an issue of Render?
It seams like it is an issue for Render, because I deployed my example on Glitch and it works.
Should I create an issue on GitHub for Render?
It is a solution for Render:
init-box2d.js
import Box2DLib from "box2d-wasm";
export let box2d = null;
export function initBox2D() {
return new Promise(resolve => {
Box2DLib({
locateFile: (url, scriptDirectory) => "file:///opt/render/project/src/node_modules/box2d-wasm/dist/umd/Box2D.simd.wasm"
}).then((re) => {
box2d = re;
resolve();
});
});
}
app.js
import { box2d, initBox2D } from "./init-box2d.js";
async function init() {
await initBox2D();
const {
b2Vec2,
b2World
} = box2d;
const gravity = new b2Vec2(0, -3);
const world = new b2World(gravity);
const g = world.GetGravity();
console.log("gravity = ", g);
}
init();
Small update for localhost:
import Box2DLib from "box2d-wasm";
export let box2d = null;
export function initBox2D(localhost = true) {
return new Promise(resolve => {
Box2DLib({
locateFile: (url, scriptDirectory) => {
if (url.endsWith(".wasm") && !localhost) {
return "file:///opt/render/project/src/node_modules/box2d-wasm/dist/umd/Box2D.simd.wasm";
}
return scriptDirectory + url;
}
}).then((re) => {
box2d = re;
resolve();
});
});
}
system
Closed
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.