iphone - Replace accelerator input with screen touch control -


I am working on an iPhone game that uses accelerometer to control I still have an apple developer program Not a user, so I can not test it on my device, so I'm trying to give some accelerometer values ​​to this game, where I tap on the screen.

> What I tried to do: I tried to keep the middle of the screen in the middle point, then the faucet from the midpoint would be XY of accelerometer. I know that these values ​​will be more than 1, and I need the value of 1 to -1, so I tried to do a lot of things to do it, I was often close, but I did not have to do this work Can get it.

In addition, I want to be there a limit, if the distance from mid to more than 100, (you know, sqrt is (dx dx + dy div) Then it will take the distance as 100, instead of like 193 or something else

Here my code is still.

  - (zero) ccTouchesMoved: (NSSet * Touching withEvent: {UIEvent *} event {if (IS_SIMULATOR) {(touch in touch with UITouch) {{CGFC} for location = [[CCDirector sharedDirector] convertToGL: [touch locationInView [touch view]]]; CGFloat dx = Location.x - middleOfScreen.x; CGFloat.dY = location.y - middleOfScreen.y; CGFloat d = sqr TF (dx * dx + DY * DY); CGFloat A = atan2 (dy, dx); CGFloat accX = acceleration value x * / CGFloat accy = / acceleration value Y * / / [[MLRF set acceleration: CC , Please, please help me.) 

Also, before someone recommends this Does not, I do not want to use iSimulate, my home internet dislike it. : (

So your question really is just how to normalize DX and DI? Value, which is DX For 160 and DE should be 240.

Otherwise, just print NSLog or all prices and find out the values. If you still do not know, post the logging code and post it Output for one touch.


Comments