TypeError: cc.Director.getInstance(...).getTouchDispatcher is not a function

When executing following code:
cc.Director.getInstance.getTouchDispatcher;

I get such an error: “TypeError: cc.Director.getInstance(…).getTouchDispatcher is not a function”

This happens even if I run the “sample” jsb projects or default code from iOS template. Adding this line crashes program…

any ideas?

getTouchDispatcher() is skipped in generate js.

check the file cocos2d-x/tools/tojs/cocos2dx.ini.

but i do not know why we need to skip this function, can anybody answer this question?

Piotr Kowalski wrote:

When executing following code:
cc.Director.getInstance.getTouchDispatcher;
>
I get such an error: “TypeError: cc.Director.getInstance(…).getTouchDispatcher is not a function”
>
This happens even if I run the “sample” jsb projects or default code from iOS template. Adding this line crashes program…
>
any ideas?

Issue http://www.cocos2d-x.org/issues/1835 was created. Thanks.

any solution for this? I’m having the same problem.

I could not find any good ‘hack’, but cocos2d devs are working on other issues on that version, so hopefully that bug will be fixed soon.

I would fix it on my own, but don’t know where to start ;]

Found this as I’m stuck without the binding in place. Trying to add a sprite as a touchable object… any ideas on workarounds in the meantime?

Bump. Do anyone know how to handle sprite as touchable object?

I have the same problem, and I need a solution for making my game work on ios/android devices.

For short-term solution:

var SubSprite = cc.Sprite.extend({

    onEnter: function() {
        this._super();
        cc.registerTargettedDelegate(0, true, this); // Use this instead.
    },

    onExit: function() {
        cc.unregisterTouchDelegate(this); // Use this instead.
        this._super();
    },

    containsTouchLocation:function (touch) {
    var getPoint = touch.getLocation();
    var myRect = this.getBoundingBox();
    return cc.rectContainsPoint(myRect, getPoint);
    },

    onTouchBegan:function(touch, event) {
        var pos = touch.getLocation();
        var id = touch.getId();
        cc.log("onTouchBegan at: " + pos.x + " " + pos.y + " Id:" + id );
        if (!this.containsTouchLocation(touch)) return false;
        return true;
    },
    onTouchMoved:function(touch, event) {
        var pos = touch.getLocation();
        var id = touch.getId();
        cc.log("onTouchMoved at: " + pos.x + " " + pos.y + " Id:" + id );
        this.setPosition(pos);
    },
    onTouchEnded:function(touch, event) {
        var pos = touch.getLocation();
        var id = touch.getId();
        cc.log("onTouchEnded at: " + pos.x + " " + pos.y + " Id:" + id );
    },
    onTouchCancelled:function(touch, event) {
        var pos = touch.getLocation();
        var id = touch.getId();
        cc.log("onTouchCancelled at: " + pos.x + " " + pos.y + " Id:" + id );
    }
});

Jose Antonio Andujar wrote:

I have the same problem, and I need a solution for making my game work on ios/android devices.

How to connect that touchable sprite to CocosBuilder?

this bug will be fixed on next cocos family release?

I’m using
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 0, true); on cocos2d-html5
and
cc.registerTargettedDelegate(0, true, this); on cocos2d-x-js

but I must change this lines everytime I want it to test on the device.

Has anyone found a solution for this issue while it isnt fixed?

cc. registerTargettedDelegate… does not work for me ! I am using cocos2d-x v3.0 pre-alpha0 and cocos2d-html5 v2.1.5

Why doesn’t registerTargettedDelegate work for you?
Joao Neves wrote:

Has anyone found a solution for this issue while it isnt fixed?
>
cc. registerTargettedDelegate… does not work for me ! I am using cocos2d-x v3.0 pre-alpha0 and cocos2d-html5 v2.1.5

There is no such function with the name cc.registerTargettedDelegate….

this is the code I am trying to make work:

@
var director = cc.Director.getInstance();

if (‘touches’ in sys.capabilities) {
//director.getTouchDispatcher().addTargetedDelegate(this, 10, true); //doest not wrk
cc.registerTargettedDelegate(0, true, this); //no such function
}
if (‘mouse’ in sys.capabilities) {
director.getMouseDispatcher().addMouseDelegate(this, 10);
}
@

I am extending cc.Node to make a clickable node… I got it working on web… but i cant make it work on device becaues i need the touch dispatcher…

My Bad Chen.

I was looking for the registerTargettedDelegate function within cocos2d-html5, I found it in cocos2d-x.
Another thing that I didn’t pay attention is that I was using onTouchesBegan instead of onTouchBegan

my bad

if (sys.platform == ‘browser’) {
cc.Director.getInstance().getTouchDispatcher()._addTargetedDelegate(this, 0, true);
}else {
cc.registerTargetedDelegate(0, true, this);
}

then you wont have to change this lines everytime while testing on the device.

Jose Antonio Andujar wrote:

this bug will be fixed on next cocos family release?
>
I’m using
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 0, true); on cocos2d-html5
and
cc.registerTargettedDelegate(0, true, this); on cocos2d-x-js
>
but I must change this lines everytime I want it to test on the device.

Thanks ke when,

I’m using something similar.

var platform = cc.Application.getInstance().getTargetPlatform();
        if (platform >= 100) {
            //web
            cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(layer, p, true);
        }else{
            //via emulador
           cc.registerTargettedDelegate(p, true, layer); // Use this instead.
        }

But this code have been solved on latest development code, I only need to registerTargetDelegate now.