From 8123ad65be46e9b7243d3429dd083638eece0127 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Fri, 4 Jan 2013 15:02:20 -0500 Subject: Made pausing easier You can now pause by tapping in the top half of the screen in any mode that supports pausing. Closes #199 --- Classes/GameMode.m | 60 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 8 deletions(-) (limited to 'Classes/GameMode.m') diff --git a/Classes/GameMode.m b/Classes/GameMode.m index 49d0053..ca269cd 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m @@ -42,14 +42,6 @@ objectFactory = [[FallingObjectFactory alloc] init]; - if ([self canPause]) - { - CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(pause)]; - CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil]; - [pauseMenu setPosition:ccp(480-8-16, 320-8-16)]; - [self addChild:pauseMenu]; - } - isPaused = NO; Class cmClass = (NSClassFromString(@"CMMotionManager")); @@ -71,6 +63,8 @@ isAccelerometerEnabled_ = YES; hasGyroscope = NO; } + + self.isTouchEnabled = YES; } return self; @@ -262,6 +256,56 @@ [cart deviceDidRotate:pitch]; } +- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + if ((!isPaused) && (!isGesturing) && ([self canPause])) + { + UITouch* touch = [touches anyObject]; + gestureStartPoint = [touch locationInView:nil]; + isGesturing = YES; + + if (gestureStartPoint.x > 160) + { + isPausing = YES; + + willPauseLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 63) width:480 height:160]; + willPauseLayer.position = ccp(0, 160); + [[[CCDirector sharedDirector] runningScene] addChild:willPauseLayer]; + } + } +} + +- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ + if (isGesturing && isPausing) + { + UITouch* touch = [touches anyObject]; + CGPoint gestureCurrentPosition = [touch locationInView:nil]; + CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2)); + + if (distance > 2) + { + [[[CCDirector sharedDirector] runningScene] removeChild:willPauseLayer cleanup:YES]; + willPauseLayer = nil; + isPausing = NO; + } + } +} + +- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +{ + if (isPausing) + { + [[[CCDirector sharedDirector] runningScene] removeChild:willPauseLayer cleanup:YES]; + willPauseLayer = nil; + isPausing = NO; + + [self pause]; + } + + isGesturing = NO; +} + - (void)dealloc { [objects release]; -- cgit 1.4.1