Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
游戏加载完成后如何.ts在 Cocos Creator 中运行脚本?它应该能够运行,而无需将组件附加到场景中的节点。
.ts
您可以将方法附加到Game将在游戏启动后运行的事件。这可以在全局范围内完成。
Game
这是一个例子:
function doSomeStuff() { console.log('Game has been initiated!'); // ... } cc.game.on(cc.game.EVENT_GAME_INITED, doSomeStuff);
如果您希望在加载游戏脚本之前更早地运行某些东西,请EVENT_ENGINE_INITED使用EVENT_GAME_INITED.
EVENT_ENGINE_INITED
EVENT_GAME_INITED