I've been working on this problem but can't find a solution, here is my situation.
The character currently moves and the users should be able to touch 2 buttons to make the character move left or right. (right button and left button) here is my code :
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInNode: _contentNode];
CGSize size = [[CCDirector sharedDirector] viewSize];
id moveLeft = [CCActionMoveBy actionWithDuration:1.5 position:ccp(-size.width/1,5)];
[moveLeft setTag:11];
id moveRight = [CCActionMoveBy actionWithDuration:1.5 position:ccp(size.width/1,5)];
[moveRight setTag:12];
if(CGRectContainsPoint([_leftButton boundingBox], touchLocation)) {
[_character runAction:moveLeft];
NSLog(@"the left button was pressed");
}
if(CGRectContainsPoint([_rightButton boundingBox], touchLocation)) {
[_character runAction:moveRight];
NSLog(@"the right button was pressed");
}
}
- (void)touchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
[_character stopActionByTag:11];
[_character stopActionByTag:12];
}
-(void) stopActionByTag:(NSInteger)tag {
[_character stopActionByTag:tag];
}
The problem now is that when i set the ground static and run the game, the character actually can penetrate the ground. Even creating static ground,the character can move across the ground. I'am making an adventure game for IOS and this feature is very important for level design. i need the ground to be static and the character should stop when there is collision between them.
Any help would be appreciative.
thanks