想請問想要New的Class為何不能放在其他文件內?

我在Start裡面想要New一個TmpPlayer的cc.class
假如我將TmpPlayer放在某個js檔案下(TestGameLogic.js), 此時New沒有問題

但是如果我將兩個檔案分開, 此時在TestGameLogic的js內去new TmpPlayer就會出錯"TmpPlayer is not defined", 如下圖, 請問該如何解決此狀況呢?

看你用繁體字,就簡單回答一下吧

你需要在另外的js檔案下使用的時候需要用 let TmpPlayer = require (‘TmpPlayer’);
你需要看下下面的鏈接
https://docs.cocos.com/creator/manual/zh/scripting/modular-script.html

1赞

感謝你的回覆以及分享, 原來是沒有Require:grin:
不過為什麼跟用繁體字有關係呀 XDD?

可能你们是港澳台的,看到繁体亲切点

1赞