implementing accelerometer to move objects


/ Published in: Objective C
Save to your folder(s)

motion of objects(labels and images)


Copy this code and paste it in your HTML
  1. #define SIGN(x) ((x < 0.0f) ? -1.0f : 1.0f)
  2.  
  3. float yaccel, yvelocity;
  4.  
  5. - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
  6.  
  7. float yy = acceleration.y;
  8. float accelDirY = SIGN(yvelocity) * -1.0f;
  9. float newDirY = SIGN(yy);
  10.  
  11. if (accelDirY == newDirY)
  12. yaccel = (abs(yaccel) + 0.99f) * SIGN(yaccel);
  13.  
  14. yvelocity = -yaccel * yy;
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.