我正试图根据iPhone中的加速度计值制作一个小球。
此代码不会构建:
-(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;
}
}
它给了我一个左值作为赋值错误的左操作数。
我尝试过100种不同的东西,但每次都失败了......这只是最近的失败。
任何人都有任何见解?
答案 0 :(得分:2)
你必须完整地设置中心:
-(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;
}
}