問題背景:
- 項目中使用了cc.AudioClip來控制聲音
- 網頁中運行項目正常,只是爆出紅色警告
- 腳本中定義正常,拖拽使用拖拽方法,項目中沒有使用url
報錯:
解決問題:
官網鏈接
emmm… 乾的漂亮,那麼看提示吧。
其他不需要動
修改
@property(cc.AudioClip)
errorSource: cc.AudioClip = null;
改爲:
@property({ type: cc.AudioClip })
errorSource: cc.AudioClip = null;
==>完美運行,解決問題!
問題尋找原因,看property源代碼:
class NewScript extends cc.Component {
property({
type: cc.Node
})
targetNode1 = null;
...
property(cc.SpriteFrame)
frame = null;
}
// above is equivalent to (上面的代碼相當於):
var NewScript = cc.Class({
properties: {
targetNode1: {
default: null,
type: cc.Node
},
...
frame: {
default: null,
type: cc.SpriteFrame
},
}
});
根據我目前的水平,看上面兩種寫法都是可以的並沒有什麼區別,不知是轉換ts的問題還是什麼問題,如果哪位大佬發現問題所在,歡迎留言告知,感激不盡!