Imitation

June_18__2014_at_1154PM

I was really impressed with how well Kero Blaster controlled and spent a few hours trying to get a similar button layout made for my next project. I was having a few problems monitoring the touches that were coming into the various functions until I realized that I could grab ahold of the touches and lock down how many touches I was monitoring and get the data that way.

This is what I came up with:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSArray* touchArray = [touches allObjects];
    UITouch* aTouch = [touchArray objectAtIndex:0];

    if (firstTouch == nil) {
        firstTouch = aTouch;
    } else if (secondTouch == nil){
        secondTouch = aTouch;
    }
    // Call to check if buttons contain touches.
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    // Call to check if buttons contain touches.
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    for (UITouch* touch in touches) {

    if (touch == firstTouch) {
            firstTouch = nil;
        }
        if (touch == secondTouch) {
            secondTouch = nil;
        }
    }
// Call to check if buttons contain touches.
}

Finally, touchesCanceled is the same as touchesEnded.

And it works! The method that checks if the touches are within the buttons handles to see if the buttons are being pressed, held or released. That matters in certain cases like jumping, where I do not want holding down the jump button to have the player hop all around.

Now, with how this is done any touch after the second will be ignored. If I hold down a finger on a button in Kero Blaster, slide it off and keep it on the screen, I can get five fingers on the screen before the buttons will not accept a touch. I am not exactly sure why this is the limit, whether that is an Apple thing or a decision made when making the game, but unless testing shows reason otherwise, limiting it to two fingers at the moment works well enough.

So now I have a decent feeling control scheme. Next is to make the physics feel really good.