Persistent error in cocos2d-js

  • fechox
    Likes 0

    Problem Description

    Hi,

    I need some help here, this error is driving me crazy: I have the follwing piece of code in the init() method of my game layer:

            topLayer = cc.Layer();
            this.addChild(topLayer); 
            cc.eventManager.addListener(touchListener, this);

     

    and here’s the event listener variable:

    var touchListener = cc.EventListener.create({
        event: cc.EventListener.TOUCH_ONE_BY_ONE,
        swallowTouches: true,
        onTouchBegan: function (touch, event) {

            cc.log("get location");

            return true;
        },

    });

    this is the error that often comes up:

    jsb: ERROR: File /Users/hejialin/IdeaProjects/eclipse/PrebuiltRuntimeJs/frameworks/runtime-src/proj.android/../../js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp: Line: 9232, Function: js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority
    Invalid Native Object
    JS: /data/data/org.cocos2dx.PrebuiltRuntimeJs/files/debugruntime/script/jsb_cocos2d.js:1643:Error: Invalid Native Object

     

    I know about retain() and release(), but it doesn’t work every time, what’s wrong here?

     

    Thanks

     

     

  • Sonar Systems admin
    Likes 0

    Where di you get this code from?


    This reply has been verified.
  • fechox
    Likes 0

    From a book I bought (Learning Cocos2d-JS Game Development)

    why?

  • Sonar Systems admin
    Likes 1


    This reply has been verified.
  • fechox
    Likes 1

    Thanks.

    It works now, all I did was to type it the whole event listener code in the init() method of my game layer, for reasons unknown it didn’t like the variable touchListener, go figure.


    This reply has been verified.
  • fechox
    Likes 1

    BTW, guys your work is great, I’ve learned tons from all the information you provide, I’m a 50 years old man who likes programming and using your website to learn cocos2d-js has made things much easier. Keep it up!


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    Great to hear our endeavours are helping people laugh


    This reply has been verified.

Login to reply