Reputation: 124
My application crashes when these blocks of code are executed. There are no errors, just warnings. The warning says, "Conflicting return type in implementation of 'ccTouchesBegan:withEvent':'void'VS'BOOL'(aka 'signed char')" Please help.
-(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;
}
Upvotes: 0
Views: 814
Reputation: 1478
there no return anything.
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
and you should use this for single touch;
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event;
it also support multi touch:
-(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;
}
you must active touch interaction first:
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
//if support multi touch you must set swallowsTouches "NO".
Upvotes: 1
Reputation: 14446
The return type on
-(BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
should be (void)
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
Upvotes: 1
Reputation: 133577
As your warning states these methods are required to return nothing (void
), not a boolean value. Try to change it and see if it fixes the warning, otherwise the problem lies in your code and not in how these methods are called.
Upvotes: 2