I'm converting the game I'm working on from UIkit to coocos2d. Using UIKIT I would use the code below code to pass the touch evens to a method. What would be the equivalent in Cocos2d?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Save the position
for (UITouch *touch in touches) {
// Send to the dispatch method, which will make sure the appropriate subview is acted upon
[self dispatchFirstTouchAtPoint:[touch locationInView:boardView] forEvent:nil];
}
}
// Saves the first position for reference when the user lets go.
- (void) dispatchFirstTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event
{
beginTouchPoint = touchPoint;
}
// Handles the continuation of a touch.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
// Send to the dispatch method, which will make sure the appropriate subview is acted upon
[self dispatchTouchEndEvent:[touch view] toPosition:[touch locationInView:boardView]];
}
}
-(void) dispatchTouchEndEvent:(UIView *)theView toPosition:(CGPoint)position
{ id sender;
int directionSwiped;
int row,column;
CGFloat xDelta = position.x - beginTouchPoint.x;
CGFloat yDelta = position.y - beginTouchPoint.y;
[self findSwipeDirectionWith: xDelta and: yDelta];
}
What would be the equivalent using cocos2d?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Save the position
for (UITouch *touch in touches) {
// Send to the dispatch method, which will make sure the appropriate subview is acted upon
[self dispatchFirstTouchAtPoint:[touch locationInView:boardView] forEvent:nil];
}
}
// Saves the first position for reference when the user lets go.
- (void) dispatchFirstTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event
{
beginTouchPoint = touchPoint;
}
// Handles the continuation of a touch.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
// Send to the dispatch method, which will make sure the appropriate subview is acted upon
[self dispatchTouchEndEvent:[touch view] toPosition:[touch locationInView:boardView]];
}
}
-(void) dispatchTouchEndEvent:(UIView *)theView toPosition:(CGPoint)position
{ id sender;
int directionSwiped;
int row,column;
CGFloat xDelta = position.x - beginTouchPoint.x;
CGFloat yDelta = position.y - beginTouchPoint.y;
[self findSwipeDirectionWith: xDelta and: yDelta];
}
I've tried to figure this out on my own, and I've spent hours on google, but I haven't come up with a workable solution.