touches offset?

Member
Posts: 129
Joined: 2009.03
Post: #1
Hello,

I'm getting touches with a Y position in the range of -7 to +472 (X position seems fine though).

Someone mentioned it could be an issue with my views' origin; but I checked the rect I use to create the view and it's 0,0,320,480.

Here's my apps' delegate code (on finished launching):

// create the window
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

// create the glView
glView = [[EAGLView alloc] initWithFrame:window.bounds];




Any suggestions?
Thanks,
Quote this message in a reply
Member
Posts: 43
Joined: 2009.10
Post: #2
Are you using:

PHP Code:
CGPoint touchLocation = [touch locationInView:glView]; 

?

And if you are putting this code in the glView class, then it would just be:

PHP Code:
CGPoint touchLocation = [touch locationInView:self]; 



Also, just an FYI, if you're making openGL view app, you probably will want to user their template that (now) goes through a view controller. There may be things down the line that you'll want to do that you can't do easily without manipulating the view controller of your view (e.g., present a video).
Quote this message in a reply
Member
Posts: 129
Joined: 2009.03
Post: #3
Hi Alerus,

I've tried [touch locationInView:self] (self is glView), and also [touch locationInView:nil]. Same result. I also tried creating a seperate view, and adding it to my window, just to capture the touches. Same results!

Not so keen to get video in to my game. In fact, it's mostly C++, I try to avoid objective C wherever possible.
Quote this message in a reply
Member
Posts: 43
Joined: 2009.10
Post: #4
Can you recreate it in a stripped down version; i.e., only the app delegate class, gl view class and touch code that registers an NSLog? If so, can you provide this code to examine?


As for a view controller, it's completely up to you. It won't slow down your rendering code any more than it is now and you can leave all the engine and rendering code in C++ even if you switch to the view controller setup. In my experience, if you don't stick with Apple's templates, you'll almost always have some headaches in the future with other things not quite working right. I *think* Game Center would also require you to work with view controllers, for instance, though I'm not sure on that since I haven't yet integrated GC into anything. It is of course your choice though!
Quote this message in a reply
Member
Posts: 129
Joined: 2009.03
Post: #5
(Jul 28, 2011 11:10 AM)alerus Wrote:  Can you recreate it in a stripped down version; i.e., only the app delegate class, gl view class and touch code that registers an NSLog? If so, can you provide this code to examine?

Yep, best way to reproduce it is to grab Apples' very own touches sample project from:
http://developer.apple.com/library/ios/s...ouches.zip

Add the following line in MyView.m (at line 167):
NSLog(@"moved : %f %f",position.x,position.y);

Compile and run the app on a device.


(Jul 28, 2011 11:10 AM)alerus Wrote:  As for a view controller, it's completely up to you. It won't slow down your rendering code any more than it is now and you can leave all the engine and rendering code in C++ even if you switch to the view controller setup. In my experience, if you don't stick with Apple's templates, you'll almost always have some headaches in the future with other things not quite working right. I *think* Game Center would also require you to work with view controllers, for instance, though I'm not sure on that since I haven't yet integrated GC into anything. It is of course your choice though!

Yeah, I think I'll create a new project using their current OpenGL template, and log out the touch posiitons, see if get more joy with that!

Thanks Smile
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2011.07
Post: #6
Actually if you put this at line 123 then you can see where your touch starts.
NSLog(@"Touch %@",touch);
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2011.07
Post: #7
add the value UIStatusBarHidden to true in your info.plist as well to hide the status bar so you can test behind it.

My range is from 0 to 470 and it begins 20 points from the edge on the task bar side and the point 470 is about 10 points from the home button edge. So I guess that's the usable range. However this still gives 480 points in a space of 460 pixels. So wtf?
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2011.07
Post: #8
Ok so using both methods you can see the touch begins at 0 and can go backwards to -6 and forward towards the home button to 470. Touches can however begin at 470 at the home button end of the screen.
Quote this message in a reply
Member
Posts: 43
Joined: 2009.10
Post: #9
So I'm using Apple's touch project that you cited (the "classic" version), but am not able to reproduce the problem.

In the touches method I added the following 2 lines (and kept the rest)
PHP Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    
    
CGPoint tp = [[touches anyObjectlocationInView:self];
    
NSLog(@"%.2f %.2f"tp.xtp.y); 


This prints out correct non-negative coordinates. When trying to click toward the left side I was able to get the x-coordinate down to a value of 1.0; I could not get it to zero, perhaps because you can't actually click on 0. Similarly, the furthest on the right I could get was 319 and the furthest y-coordinate for the bottom was 479. The furthest to the top I could get was 20, because above that is the status bar which disables the clicking.


If we're getting different results that's quite bizarre. Can you try that code I listed exactly in the classic project just to make sure?


Oh, and I did try your moved code as well, but didn't get negative numbers then either :-/


I also tried on the device with similar results. It's much more difficult to hit the bounds (I believe because on the device it's doing an averaging of all the points being touched), but still no negative numbers.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2011.07
Post: #10
I get the same values with your output as with mine. Add the value UIStatusBarHidden to true in your info.plist as well to hide the status bar so you can test behind it. I can only get values on initial tap from 0 to 470 and then at the 0 side I can drag another -6 points to the edge. It won't detect a tap in that region so your code won't show anything below 0.
And it works normally on the simulator. This problem is only occurring on the device itself.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2011.07
Post: #11
From Apple:

"Apple is aware of the problem, and a bug report has been filed. This is possibly related to the OS's tendency to register touches several pixels above the physical contact point. It's not always possible to see values at the very extremes of the device due to a lack of sensors beyond the edges of the screen.

For the time being, you could work around the issue by offsetting the touches back to the expected range. Make sure to key that offsetting code to the version of iOS on which they determined the bounds, since that will change when/if Apple fixes this bug."
Quote this message in a reply
Moderator
Posts: 434
Joined: 2002.09
Post: #12
In practice I've found it best not put small touch areas near the edge of the screen, and/or to allow them to detect touches that are "close enough" (i.e. adding an invisible touch detection area around the button.)

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  co-processor offset out of range spuckfunkel 18 14,985 Jan 22, 2011 07:14 PM
Last Post: headkaze
  Offset the text in a UITextField??? Toontingy 0 4,571 Apr 25, 2010 08:44 PM
Last Post: Toontingy
  How to get number of active touches? Rasterman 8 7,286 Apr 21, 2010 03:56 PM
Last Post: longjumper
  not getting touches for top 20 pixels Rasterman 10 6,332 Apr 8, 2010 01:00 AM
Last Post: fattoh
  Touches are slowing down game Jamie W 8 5,569 Mar 26, 2010 03:41 PM
Last Post: Jamie W