0
嗨標題預先總結了它,它使用的是加速度計,但它只是繼續離開屏幕,IM 15,我是有一堆麻煩試圖讓它停在edge.here是我的視圖controller.m文件代碼。使用移動的UIImageview製作opengl遊戲,但我可以讓它停在屏幕邊緣
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize person, delta;
- (void)viewDidLoad
{
UIAccelerometer *accel =[UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = 1.0f/60.0f;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration{
NSLog(@"x : %g", acceleration.x);
NSLog(@"y : %g", acceleration.y);
NSLog(@"z : %g", acceleration.z);
delta.x = acceleration.y *50;
// delta.x = acceleration.x *8;
person.center = CGPointMake(person.center.x + delta.x,person.center.y + delta.y);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我補充說,現在我得到的錯誤表達式不能分配給這一點的代碼。 person.center.x = MAX(minCenterX,person.center.x); –
我只需要它在橫向停止左/右邊緣。 –
啊,是的,你必須一次性設定整個'center'值。我更新了這篇文章。 –