0

我正在制作一个学习游戏,用于向幼儿园的孩子们教授数字。它需要一些像这样的动画,但我无法在画布中顺利实现这个动画。

我希望使用这条虚线出现完全相同的动画。

请指导我执行这种类型的动画。

4

1 回答 1

0

What you need is:

  • a loop
  • path definition

The loop should update current image position and rotation. Then draw the updated animation on a screen. You can just override dispatchDraw method and call invalidate at the very end of it. You can update position right before drawing. Your case is similar to game programming, so you can look for articles about game loops.

Path definition should allow you to calculate position depending on time. Fo example you can use Bezier curves. Bezier curve equation is parametric and the parameter is 'time'. Using the animation time gives you smooth movement along the path.

Example of a generic game loop: http://www.gameprogblog.com/generic-game-loop/

Bezier curve: http://en.wikipedia.org/wiki/B%C3%A9zier_curve

long time = System.currentTimeMillis();
protected void dispatchDraw(Canvas canvas) {
    PointF pos = getBezierPos(System.currentTimeMillis() - time);
    drawImage(pos);
    invalidate();
}
于 2013-07-16T09:28:39.257 回答