modified touch interface to be a little more fluid on iOS

This commit is contained in:
techdragon.nguyen@gmail.com
2011-12-16 11:09:40 +00:00
parent 4b137e0b6b
commit 3bfb68f96c
3 changed files with 41 additions and 25 deletions

View File

@@ -8,7 +8,7 @@
// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. // This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
// The view content is basically an EAGL surface you render your OpenGL scene into. // The view content is basically an EAGL surface you render your OpenGL scene into.
// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. // Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
@interface EAGLView : UIView<AdWhirlDelegate> @interface EAGLView : UIView<AdWhirlDelegate,UIGestureRecognizerDelegate>
{ {
AdWhirlView *adView; AdWhirlView *adView;
//This is a trick, AdMob uses a viewController to display its Ads, trust me, you'll need this //This is a trick, AdMob uses a viewController to display its Ads, trust me, you'll need this

View File

@@ -23,12 +23,6 @@ static JGameLauncher* g_launcher = NULL;
CGFloat lastScale; CGFloat lastScale;
CGFloat lastRotation; CGFloat lastRotation;
CGFloat firstX;
CGFloat firstY;
CGFloat currentX;
CGFloat currentY;
void JGECreateDefaultBindings() void JGECreateDefaultBindings()
{ {
} }
@@ -109,6 +103,7 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
/* /*
create swipe handlers for single swipe create swipe handlers for single swipe
*/ */
UISwipeGestureRecognizer *singleFlickGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @selector(handleFlickGesture:)]; UISwipeGestureRecognizer *singleFlickGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @selector(handleFlickGesture:)];
singleFlickGestureRecognizer.numberOfTouchesRequired = 1; singleFlickGestureRecognizer.numberOfTouchesRequired = 1;
singleFlickGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; singleFlickGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
@@ -230,6 +225,10 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
[self addGestureRecognizer: singleTapRecognizer]; [self addGestureRecognizer: singleTapRecognizer];
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector(handlePanMotion:)];
[panGestureRecognizer setMaximumNumberOfTouches: 1];
[self addGestureRecognizer: panGestureRecognizer];
[panGestureRecognizer release];
/* /*
Use the pinch gesture recognizer to zoom in and out of a location on the screen. Use the pinch gesture recognizer to zoom in and out of a location on the screen.
@@ -403,6 +402,36 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
#pragma mark Gesture Recognizer callbacks #pragma mark Gesture Recognizer callbacks
- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
- (void)handlePanMotion: (UIPanGestureRecognizer *) panGesture
{
[[[panGesture view] layer] removeAllAnimations];
currentLocation = [panGesture locationInView: self];
ES2Renderer* es2renderer = (ES2Renderer*)renderer;
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
int xOffset = ((currentLocation.x-es2renderer.viewPort.left)*SCREEN_WIDTH)/actualWidth;
int yOffset = ((currentLocation.y-es2renderer.viewPort.top)*SCREEN_HEIGHT)/actualHeight;
CGPoint newLocation = CGPointMake(xOffset, yOffset);
if (panGesture.state == UIGestureRecognizerStateBegan || panGesture.state == UIGestureRecognizerStateChanged)
{
g_engine->LeftClicked(newLocation.x, newLocation.y);
}
else if ( [panGesture state] == UIGestureRecognizerStateEnded)
{
CGPoint velocity = [panGesture velocityInView:panGesture.view.superview];
if (!(( ((int)abs( (int) velocity.x)) > 300) || ((int) (abs( (int) velocity.y)) > 300)))
g_engine->HoldKey_NoRepeat( JGE_BTN_OK );
}
}
- (void)handleSingleTap: (UITapGestureRecognizer *) recognizer { - (void)handleSingleTap: (UITapGestureRecognizer *) recognizer {
[[[recognizer view] layer] removeAllAnimations]; [[[recognizer view] layer] removeAllAnimations];
currentLocation = [recognizer locationInView: self]; currentLocation = [recognizer locationInView: self];
@@ -421,18 +450,9 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
int yOffset = ((currentLocation.y-es2renderer.viewPort.top)*SCREEN_HEIGHT)/actualHeight; int yOffset = ((currentLocation.y-es2renderer.viewPort.top)*SCREEN_HEIGHT)/actualHeight;
g_engine->LeftClicked(xOffset, yOffset); g_engine->LeftClicked(xOffset, yOffset);
// doesn't work as expected. Need to figure out correct algorithm. Double tap or double swipe down will execute OK button.
NSInteger xDiff = abs(static_cast<int>(currentX) - xOffset);
NSInteger yDiff = abs(static_cast<int>(currentY) - yOffset);
if (xDiff <= 60 && yDiff <= 60) if ( recognizer.state == UIGestureRecognizerStateEnded )
{
g_engine->HoldKey_NoRepeat(JGE_BTN_OK); g_engine->HoldKey_NoRepeat(JGE_BTN_OK);
}
currentX = xOffset;
currentY = yOffset;
} }
else if(currentLocation.y < es2renderer.viewPort.top) { else if(currentLocation.y < es2renderer.viewPort.top) {
@@ -471,12 +491,6 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
default: default:
break; break;
} }
/*
CGPoint translatedPoint = [recognizer locationInView: self];
currentX = translatedPoint.x;
currentY = translatedPoint.y;
g_engine->LeftClicked( currentX, currentY);
*/
} }
- (void)handleHand:(UITapGestureRecognizer *)recognizer { - (void)handleHand:(UITapGestureRecognizer *)recognizer {
@@ -532,6 +546,8 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
} }
#pragma mark - #pragma mark -
#include "GameOptions.h" #include "GameOptions.h"
#pragma mark Keyboard related methods #pragma mark Keyboard related methods

View File

@@ -2447,7 +2447,7 @@
./minizip, ./minizip,
"iOS/Reachability/Reachability\\ 2.0.4ddg/DDG\\ Reachability/Classes/", "iOS/Reachability/Reachability\\ 2.0.4ddg/DDG\\ Reachability/Classes/",
); );
INFOPLIST_FILE = "wagic copy-Info.plist"; INFOPLIST_FILE = "wagic-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.0; IPHONEOS_DEPLOYMENT_TARGET = 4.0;
LIBRARY_SEARCH_PATHS = ( LIBRARY_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
@@ -2492,7 +2492,7 @@
./minizip, ./minizip,
"iOS/Reachability/Reachability\\ 2.0.4ddg/DDG\\ Reachability/Classes/", "iOS/Reachability/Reachability\\ 2.0.4ddg/DDG\\ Reachability/Classes/",
); );
INFOPLIST_FILE = "wagic copy-Info.plist"; INFOPLIST_FILE = "wagic-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.0; IPHONEOS_DEPLOYMENT_TARGET = 4.0;
LIBRARY_SEARCH_PATHS = ( LIBRARY_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",