A Game's Own Files#
Three helpers for the files that ship alongside your source. They take a bare name and work out where it actually lives, which differs between a game served from play.onejs.com and a project on disk.
For everything else, including JSON, text, and the platform rules that make StreamingAssets a URL rather than a directory on Android and WebGL, use the general loaders on the assets guide. oj does not wrap those and does not need to.
assetUrl#
import { assetUrl } from "oj"
const url = assetUrl("pop.wav")Resolves a bare name to a URL. This is the one to reach for whenever an API wants a URL rather than a name. audio.load is the common case, and it is deliberate that it takes a URL and makes you say which one:
import { audio, assetUrl } from "oj"
const sound = await audio.load(assetUrl("pop.wav"))loadTexture and useTexture#
import { useTexture, View } from "oj"
function Sprite() {
const tex = useTexture("player.png")
if (tex === null) return <View />
return <View style={{ backgroundImage: tex }} />
}loadTexture(name) returns a promise. useTexture(name) is the hook form, returning null until the texture resolves and the loaded texture afterwards, so render a placeholder for that first pass rather than assuming it is there.
Both take a bare name and resolve it for you, which is what separates them from audio.load. If you find yourself passing a full URL to useTexture, you probably want assetUrl at the other call site instead.