执行这些代码块时,我的应用程序崩溃了。没有错误,只是警告。警告说,“'ccTouchesBegan:withEvent':'void'VS'BOOL'(又名'签名字母')的执行中的回复类型冲突”请帮忙。
-(BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
return YES;
}
-(BOOL) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:[myTouch view]];
point = [[CCDirector sharedDirector] convertToGL:point];
CCNode *player = [self getChildByTag:kTagPlayer];
[player setPosition:point];
CCNode *computer = [self getChildByTag:kTagComputer];
[computer runAction:[CCMoveTo actionWithDuration:3.0
position:ccp(player.position.x, player.position.y)]
];
return YES;
}
答案 0 :(得分:2)
正如您的警告所述,这些方法需要不返回任何内容(void
),而不是布尔值。尝试更改它,看看它是否修复了警告,否则问题出在代码中,而不是如何调用这些方法。
答案 1 :(得分:1)
上的返回类型
-(BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
应该是(无效)
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
答案 2 :(得分:1)
没有任何回报。
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
你应该用它来单次触摸;
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event;
它还支持多点触控:
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
NSArray *allTouches = [[event allTouches] allObjects];
for (int i=0; i<[allTouches count];i++) {
if ([some conditions]) {
CGPoint position = [(UITouch*)[allTouches objectAtIndex:i] locationInView:[[CCDirector sharedDirector]openGLView]];
position.y = [[CCDirector sharedDirector]winSize].height - position.y;
//deal with the position;
return TRUE;
}
}
return FALSE;
}
您必须先激活触摸互动:
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
//if support multi touch you must set swallowsTouches "NO".