views:

193

answers:

1

I am trying to make a little ball that rolls around based on the accelerometer values in the iPhone.

This code will not build:

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
 if(difficulty == @"Easy")
 {
  CGFloat newX = (CGFloat)(ball.frame.origin.x + (CGFloat)acceleration.x);
  CGFloat newY = (CGFloat)(ball.frame.origin.y + (CGFloat)acceleration.y);
  ball.frame.origin.x = newX;
  ball.frame.origin.y = newY;
 }
}

It gives me an lvalue required as left operand of assignment error.

I've tried 100 different things and I fail every time...This is just the latest failure.

Anyone have any insight?

+2  A: 

You have to set the center in it's entirety:

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
 if(difficulty == @"easy")
 {
  CFPoint center = ball.center;
  CGFloat center.x = (CGFloat)(ball.x + (CGFloat)acceleration.x);
  CGFloat center.y = (CGFloat)(ball.y + (CGFloat)acceleration.y);
  ball.center = center;
}
}
iWasRobbed