我正在尝试用javascript编写游戏引擎,我想做的是在游戏代码执行之前加载所有引擎代码。现在,这只是第一步,因为我还想做的是将游戏代码中的所有引擎代码加载到一个文件中。所以我会有一个引导文件,我在其中加载所有引擎代码,返回主游戏对象并将其返回到游戏代码中。
define(['engine'[,...[]]], function(engine){
// do what you want in order for you to make a game
});
在我的引擎文件中,我将加载所有引擎代码,例如:
requirejs.config({
baseUrl: '/js/libraries/engine',
paths: {
message : "message",
debug : "debug",
vector2 : "helpers/vector2",
settings : "settings",
engine : "engine",
loop : "loop",
extra : "extras",
scene : "scene",
scenemanager : "scenemanager",
audio : "audio",
input : "input",
canvas : "canvas",
drawable : "drawables/drawable",
sprite : "drawables/sprite",
animation : "drawables/animation",
boxcollider : "colliders/boxcollider",
spherecollider : "colliders/spherecollider",
actor : "actor",
world : "world"
}
});
require(["message", "debug", "vector2", "settings", "engine", "loop", "extra", "scene", "scenemanager",
"audio", "input","canvas","drawable","sprite","animation","boxcollider", "spherecollider", "actor", "world"]
, function(
message, debug, vector2, settings, engine, loop, extra, scene, scenemanager,
audio, input, canvas, drawable, sprite, animation, boxcollider, spherecollider, actor, world)
{
return engine;
}
);
所以基本上,engine.js 文件将成为引擎代码的清单,我只想加载 engine.js 文件以访问其中定义的所有组件。我只是不知道目前该怎么做。