Graphics Reference
In-Depth Information
forMode
:
NSDefaultRunLoopMode
];
//update gravity using accelerometer
[
UIAccelerometer
sharedAccelerometer
].
delegate
=
self
;
[
UIAccelerometer
sharedAccelerometer
].
updateInterval
=
1
/
60.0
;
}
- (
void
)accelerometer:(
UIAccelerometer
*)accelerometer
didAccelerate:(
UIAcceleration
*)acceleration
{
//update gravity
cpSpaceSetGravity
(
self
.
space
,
cpv
(acceleration.
y
*
GRAVITY
,
-acceleration.
x
*
GRAVITY
));
}
Figure 11.2
Multiple crates interacting with realistic physics
Simulation Time and Fixed Time Steps
Calculating the frame duration and using it to advance the animation was a good solution
for the easing-based animation, but it's not ideal for advancing our physics simulation.
Having a variable time step for a physics simulation is a bad thing for two reasons: