FROM : Jens Alfke
DATE : Wed Apr 02 00:17:41 2008
On 1 Apr '08, at 10:44 AM, Jesse Grosjean wrote:
> n my app it seems like it would be simpler to just setup a timer and
> just directly update the ships position based on it's velocity for
> each time interval from my timer. I'd still want to use the built in
> core animation animations for other properties such as transparency,
> filters, etc. But for layer position it seems like it would be
> easiest to control that directly...
You're right. Last year I was fooling around with hooking CA up to a
2D physics engine, and I just let the engine tell me where and when to
position the objects, and set their position properties accordingly.
For best results, disable animations for this, otherwise CA will try
to interpolate positions and things won't move correctly. I was doing
this by using a CATransaction to disable all animations, but I think
in hindsight it might be better just to to adjust the layers'
animation dictionaries to clear out the animation for the "position"
key.
(Using an existing physics engine is a great way to go, if you want to
do this. I was using Box2D, but there's another similar one called
Chipmunk. The math for this stuff gets really hairy — I've just
started reading "Physics For Game Developers", and it's fascinating
but I'm so glad I don't have to implement that myself!)
—Jens
DATE : Wed Apr 02 00:17:41 2008
On 1 Apr '08, at 10:44 AM, Jesse Grosjean wrote:
> n my app it seems like it would be simpler to just setup a timer and
> just directly update the ships position based on it's velocity for
> each time interval from my timer. I'd still want to use the built in
> core animation animations for other properties such as transparency,
> filters, etc. But for layer position it seems like it would be
> easiest to control that directly...
You're right. Last year I was fooling around with hooking CA up to a
2D physics engine, and I just let the engine tell me where and when to
position the objects, and set their position properties accordingly.
For best results, disable animations for this, otherwise CA will try
to interpolate positions and things won't move correctly. I was doing
this by using a CATransaction to disable all animations, but I think
in hindsight it might be better just to to adjust the layers'
animation dictionaries to clear out the animation for the "position"
key.
(Using an existing physics engine is a great way to go, if you want to
do this. I was using Box2D, but there's another similar one called
Chipmunk. The math for this stuff gets really hairy — I've just
started reading "Physics For Game Developers", and it's fascinating
but I'm so glad I don't have to implement that myself!)
—Jens
| Related mails | Author | Date |
|---|---|---|
| Jesse Grosjean | Apr 1, 19:44 | |
| Jens Alfke | Apr 2, 00:17 | |
| Jesse Grosjean | Apr 2, 00:54 | |
| Jens Alfke | Apr 2, 01:22 |






Cocoa mail archive

