I was able to get the touch working correctly, although, due to your code structure, I wasn't able to do it the way I intended it. Here are the steps you need to take...
In ZonesController.m:
- Replace addTouchEvent: method with...
-(void)addTouchEvent {
[[SPStage mainStage] addEventListener:@selector(onTouchEvent:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
}
- Replace removeTouchEvent method with...
-(void)removeTouchEvent {
[[SPStage mainStage] removeEventListener:@selector(onTouchEvent:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
}
- Replace onTouchEvent: method with...
- (void)onTouchEvent:(SPTouchEvent*)event
{
//if(![GameSettings getAllowControls]) return nil;
NSArray *touchesBegin = [[event touchesWithTarget:[SPStage mainStage] andPhase:SPTouchPhaseBegan] allObjects];
NSArray *touchesEnd = [[event touchesWithTarget:[SPStage mainStage] andPhase:SPTouchPhaseEnded] allObjects];
if(touchesBegin.count){
for(int i=0; i<touchesBegin.count; i++){
SPTouch *touch = [touchesBegin objectAtIndex:i];
for (TouchableZone *touchableZone in zonesArray) {
SHAlphaImage *image = touchableZone.spImage;
SPPoint *location = [touch locationInSpace:image];
if ([image alphaOfPixelWithX:location.x y:location.y] >= image.allowTouchOnAlpha) {
lastPressedZoneIndex = [touchableZone getId];
[touchableZone click];
break;
}
}
}
}
if(touchesEnd.count){
for(int i=0; i<touchesEnd.count; i++){
SPTouch *touch = [touchesEnd objectAtIndex:i];
for (TouchableZone *touchableZone in zonesArray) {
SHAlphaImage *image = touchableZone.spImage;
SPPoint *location = [touch locationInSpace:image];
if ([image alphaOfPixelWithX:location.x y:location.y] >= image.allowTouchOnAlpha) {
lastPressedZoneIndex = [touchableZone getId];
[touchableZone unclick];
break;
}
}
}
}
}
In TouchableZones.h:
- Add this property...
@property (nonatomic, readonly) SHAlphaImage *spImage;
In TouchableZones.m:
- Add this synthesize...
@synthesize spImage;
... and that should do it. The key problems you had were: First, the touches weren't always caught by the zone controller sprite, so you have to handle to touches on the stage instead. And second, the target of the touches weren't always TouchableZone, so instead you should just loop each TouchableZone to make sure the touch is within them.
BTW, I love the background animations. It's very pretty and entertaining.