使用CCTouchDispatcher Cocos2d 2.0 Beta-2 ARC
问题描述:
我使用cocos2d 2.0 BETA 2.0 [最新的一个]创建一个游戏。我需要在其他类中添加一个操纵杆。所以我在我的第二个类中称为CCTouchDispatcher。但我不能这样调用:
I am creating a game with cocos2d 2.0 BETA 2.0 [The newest one]. And i need to add a joystick in other class. so I call this "CCTouchDispatcher" in my second class. But I can't call like this:
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
所以我做了这个:
_tocuhDispatcher = [[CCTouchDispatcher alloc] init];
[_tocuhDispatcher addTargetedDelegate:self priority:0 swallowsTouches:YES];
但仍无法检测到触摸。如果我在HelloWorldLayer中启用触摸,我可以移动我的对象与触摸,但没有操纵杆不工作
But still can't detect the touches. If I enable the touches in my HelloWorldLayer I could move my object with the touches but no the joystick doesn't work
我能做什么?
答
CCDirector *director = [CCDirector sharedDirector];
[[director touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];