【cocos2d-js官方文檔】十、log

api改動情況,左邊爲新增,右邊爲原來的。

cc.log  不變
cc.warn 新增
cc.error 新增
cc.assert <-- cc.Assert

此次改造有以下幾點原因:

  • 添加原來沒有的api:cc.warn、cc.error。

  • 修改cc.Assert名稱,使其符合開發規範。

新的api的使用範例:

cc.log("this is a log");
cc.log("this is a log for %s", "Cocos2d-html5");

cc.warn("this is a waring");
cc.warn("this is a waring for %s", "Cocos2d-html5");

cc.error("this is an error");
cc.error("this is an error for %s", "Cocos2d-html5");

cc.assert(false, "this is an assert");
cc.assert(false, "this is an assert for %s", "Cocos2d-html5");

然後今後會定義出msgCode.js

cc.msgCode = {
    log1 : "this is a log",
    log2 : "this is a log for %s",
    warn1 : "this is a waring",
    warn2 : "this is a waring for %s",
    error1 : "this is an error",
    error2 : "this is an error for %s",
    assert1 : "this is an assert",
    assert2 : "this is an assert for %s",
    throw1 : "this is an throw",
    throw2 : "this is an throw for %s", "Cocos2d-html5"
}

這樣一來可以讓消息字符串等到最大程度的複用並且利於管理。


轉載:http://www.douapp.com/post/2454

發佈了51 篇原創文章 · 獲贊 73 · 訪問量 52萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章