-(id) init { if( (self=[super init]) ) { [self setAccelerometerEnabled:YES]; } } - (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { CGPoint pos = sprite.position; pos.x += acceleration.x * 10; pos.y += acceleration.y * 10; sprite.position = pos; }だが、これでは反応が鈍い
スムーズに動かすためには下記に修正
-(id) init { if( (self=[super init]) ) { [self setAccelerometerEnabled:YES]; //updateをフレーム毎に呼び出す [self scheduleUpdate]; } } - (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { //速度の制御 float deceleration = 0.4f; //減速の制御 float sensitivity = 6.0f; //感度 //速度調整 moveSpeed.x = moveSpeed.x * deceleration + acceleration.x * sensitivity; moveSpeed.y = moveSpeed.y * deceleration + acceleration.y * sensitivity; } -(void)update:(ccTime)delta { CGPoint pos = sprite.position; pos.x += moveSpeed.x; pos.y += moveSpeed.y; sprite.position = pos; }
0 件のコメント:
コメントを投稿