objective c - Accelerometer & Calibration - iPhone SDK -


I need to use the accelerometer functionality in my iPhone game. I need to move an image by tilting the device . However, most of the video on YouTube shows the tilt feature, which somehow forget to include inverted and calibration. Whatever the situation they are in. Are the users who want to fix their equipment? Anyone know how should I get started on this?

Your help is highly appreciated,

Kevin

I have created an app like this once, I will post it here, but it is for iOS 4 ...

To check:

  int tapCount = 0; - (zero) Cancel doubletap {if (tabcount & lt; 2) {tapCount = 0; }} - (zero) reset {{[NSUserDefaults Standard User Defaults] Setflat: 0 for KA: @ "X-Calibrate"]; [[NSUserDefaults standard standard defaults] Set Fleet: 0fork: @ "Y-Calibrate"]; UIAlertView * Warning = [[UIAlertView alloc] initWithTitle: @ "Reset!" Message: @ "Reset calibration." Representative: Cancel zeroTuttonite: @ "OK." OtherButtonTitles: zero]; [Alerts show]; [Warning issued]; } - Check (zero) {if (tabcount == 3) {tapCount = 0; Return; } [[NSUserDefaults Standard User Defaults] Setflat: Excel Phracke: @ "X-Calibrate"]; [[NSUserDefaults Standard Standard Defaults] Set Float: Excel Farke: @ "Y-Calibrate"]; UIAlertView * Warning = [[UIAlertView alloc] initWithTitle: @ "Calibrated!" Message: [NSString stringWithFormat: @ "Calibrated to:% .2f% .2f.", AccelX, accelY] Rep:: CancelButtonTitle zero: ". OK" @otherButtonTitles: zero]; [Alerts show]; [Warning issued]; Tapacount = 0; } - (BOOL) can do the FirstSponder {Return; } - (zero) touchesEnded: (NSSet *) withEvent touches: (UIEvent *) event {NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector (cancelDoubleTap) userInfo: repeats not equal to: NO] ; Tapacount ++; If (tapacount == 3) {[invalid timer]; [Auto reset]; Return; } If (Tapcount == 2) {[Invalid timer]; Timer = [nstmeter scheduled timer with interval: 0.5 target: auto selector: @ selector (calibrate) user information: zero repeats: no]; }}  

and ...

  - (bool) Application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {but = [[ UIButton alloc] initWithFrame: window.frame]; [But addTarget: Self-Proceedings: @Selector (TouchAdWords: Attentiveness: Controll events for: UIControll Event Touchup Inside]; [Add windowSubview: but]; // Override Point for optimization after application launch. Box = [[UIView alloc] initWithFrame: CGRectMake (self.window.center.x - 50, self.window.center.y - 50, 100, 100)]; [Window-making and knowledgeable]; Box.backgroundColor = [UIColor colorWithRed: 1.0 green: 0.0 blue: 0.0 alpha: 0.75]; [Add windowviewview: box]; [[UIAccelerometer shared accelerometer] Set Deliaget: Self]; [[UIAccelerometer Share Accelerometer] setUpdateInterval: (1 / 100.0)]; Slider = [[UISlider alloc] initWithFrame: CGRectMake (20, 438, 280, 22)]; [Slider set value value: 2.0]; [Slider setmaxium value: 50.0]; [Add Window: Slider]; Yes come back }  

.h file:

  #import & lt; UIKit / UIKit.h & gt; @ Interface Tyler App Delegate: NSObact & lt; UIApplicationDelegate, UIAccelerometerDelegate & gt; {UIWindow * window; UIView * box; UISlider * slider; UIButton * but; } @protecti (nontomic, raten) IBOutlet UIButton * but; @protecti (nanatomic, retten) IBOutlet UISlider * slider; @protecti (nontomic, retain) IBOutlet UIView * box; @ Property (Nonomatic, Retaining) IBOutlet UIWindow * Window; @end  

Move code:

  - (zero) moveBoxByX: (name) x byy: (name) y {float newX = box.center . X + x; Float newY = box center.y + y; If (NewX & Lt; 50) NewX = 50; If (newx> 270) newx = 270; If (new and 50) new = 50; If (New Y> 430) newY = 430; Box.center = CG PointMake (new X, New Y); }  

Most of the time should work.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -