iMiniB3D Touch

BlitzMax Forums/MiniB3D Module/iMiniB3D Touch

Rob Pearmain(Posted 2012) [#1]
Hi,

I am really struggling with this one, and I am sure the answer is simple.

I want to detect when the screen is touched and get the X,Y co-ordinate.

I have looked at the Zombie tutorial, and am struggling to understand how it works (What with the pick_quad etc).

I simply want:

if(Screen_Touched) x,y

    for(int i=0;i<Touch::CountTouches();i++){
        
        
		if(Touch::TouchHit(i)){
            
			float x=Touch::TouchX(i);
			float y=Touch::TouchY(i);
			float z=0.0;
            
            NSLog([[NSString stringWithFormat:@"%d %d",x,y] UTF8String]);
			            
		}
        
	}


The above simply bring back 0 for X, and a huge number for Y (e.g. 102323232)

Help?

Last edited 2012


Floyd(Posted 2012) [#2]
It's probably displayed incorrectly because %d is for integer values. Try %f for float. That's how it would be for C/C++ printf.

As a reality check I would also put a known value, other than 0, into z and display that as well.

Last edited 2012


ima747(Posted 2012) [#3]
As floyd said use %f for floats. Also if all you want is the screen x/y I find it's usually better to trap the touch inputs myself since you can make a system with a lot less overhead that also tracks multiple touches more uniquely. The system in iMiniB3D tracks the touches by count, rather than by touch, meaning if you touch down twice, then lift the first touch the second becomes the first because there's only 1 touch down...


Rob Pearmain(Posted 2012) [#4]
It only seems to work for Y between 460 and 480???

So, if I click anywhere in the top 10% of the phone (Emulator) it registers the click, but not between 0 and 460


ima747(Posted 2012) [#5]
Sounds like a possible layout problem with your view... try putting some NSLogs into the EAGLView code relating to touches. if the view doesn't get it it doesn't pass it on to the touch handler in iMiniB3D


simonh(Posted 2012) [#6]
460-480 is normally the range you can't touch (due to the status bar), so you might have something the wrong way around somewhere.


Rob Pearmain(Posted 2012) [#7]
Found it, thanks for all your help.

It was because I was trying to be clever and work around the warning where it says "Missing Root Controller" by adding a root controller manually.

This got in the way of the touch messages, so crazily only the touches to the status bar area got through.

All solved, thanks again

Rob