cocos creator 2.0的 getPosition 好像有bug

  • Creator 版本:

  • 目标平台: 模拟器

  • 详细报错信息,包含调用堆栈:
    Simulator: E/jswrapper (270): ERROR: Uncaught TypeError: Cannot read property ‘toFixed’ of null, location: src/cocos2d-jsb.js:0:0
    STACK:
    [0]248.proto.toString@src/cocos2d-jsb.js:44071
    [1]__realTypeOfObj@src/cocos2d-jsb.js:78650
    [2]Vec2@src/cocos2d-jsb.js:43836
    [3]getPosition@src/cocos2d-jsb.js:8080
    [4]_showLoading@assets/Script/component/Caps_Image.js:71
    [5]loadImg@assets/Script/component/Caps_Image.js:27
    [6]_loadList@assets/Script/ui/home/ui_my_prize_list.js:185
    [7]anonymous@assets/Script/ui/home/ui_my_prize_list.js:147
    [8]SendData.request.onreadystatechange@assets/Script/caps/http_request.js:31
    at HTMLElement.print-simulator-log (D:\CocosCreator\resources\app.asar\editor\builtin\scene\panel\messages\scene.js:1:1487)
    at Object.e._dispatch (D:\CocosCreator\resources\app.asar\editor-framework\lib\renderer\panel.js:1:1941)
    at EventEmitter.o.on.s (D:\CocosCreator\resources\app.asar\editor-framework\lib\renderer\ipc.js:1:2917)
    at emitMany (events.js:127:13)
    at EventEmitter.emit (events.js:204:7)

  • 重现方式:
    读取任意一个node的位置= =
    let a = this._loadingrefresh.getPosition()

  • 出现概率:100%

  • 额外线索:从 1.6版本升级过来遇到的问题 2.0版本吧 getPositionX给删除了以后 本来想用getPosition().x的,但cocos2d-jsb一直报 Cannot read property ‘toFixed’ of null的错误

2.0升级指南中有说setter 和getter方法弃用了,直接用x和y试试

1赞

谢谢,原来直接用node.x,替代node.getPositionX()就行 而不是 用node.getPosition().x替代node.getPositionX()

我遇到这种情况