Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Animation formula for movement

I have a formula for setting x and y of an object at every frame. In a classic for (i=0; i < x; i++) loop, I can bind it to the i value and calculate x and y values based on the current value of i that represents the passing of time.

I intended to use it with a NSTimer object and update the coordinate points at every tick, but I've seen that NSTimer is descouraged for animations.

Can I do the same with Core Animation? Instead of the standard "from here to there in given seconds", I would need a method to "update the position with this formula".

like image 710
pistacchio Avatar asked May 06 '11 06:05

pistacchio


1 Answers

If you can model your function with a cubic Bézier curve, you can create a custom CAMediaTimingFunction instance and assign it to the animation's timingFunction property.

If a Bézier curve does not work, a CAKeyframeAnimation might indeed work.

like image 177
Ole Begemann Avatar answered Sep 29 '22 11:09

Ole Begemann