CocosCreator報錯Please change the definition of property '***' in class 'NewClass'. Since v1.1

問題背景:

  1. 項目中使用了cc.AudioClip來控制聲音
  2. 網頁中運行項目正常,只是爆出紅色警告
  3. 腳本中定義正常,拖拽使用拖拽方法,項目中沒有使用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的問題還是什麼問題,如果哪位大佬發現問題所在,歡迎留言告知,感激不盡!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章