【问题标题】:move an object follow a user-defined path on Android在 Android 上按照用户定义的路径移动对象
【发布时间】:2011-03-14 15:38:45
【问题描述】:

我应该使用什么算法或技术来使对象遵循用户在屏幕上绘制的路径?

【问题讨论】:

    标签: android algorithm graphics path


    【解决方案1】:

    下面的例子创建了一个 PATH 用于在 Circle Path 上显示 TEXT:

    // create a path
    Path circle = new Path();
    circle.addCircle(centerX, centerY, radius, Direction.CW);
    
    // set the color and font size
    Paint paint = new Paint();
    paint.setColor(Color.BLUE);
    paint.setTextSize(30);
    paint.setAntiAlias(true);
    
    // draw the text along the circle
    canvas.drawTextOnPath(QUOTE, circle, 0, 30, paint);
    

    可以参考全文 Example Here

    而对于动画,Android SDK 提供的动画主要有 4 种类型:

    1. AlphaAnimation - 透明度变化
    2. RotateAnimation – 旋转
    3. ScaleAnimation – 增长或缩小
    4. TranslateAnimation - 位置变化

    有关创建动画序列,请参阅 Example Here

    对于不同类型的动画示例,例如帧动画(如在 Flash 中)、列表动画等。可以参考Animations Types EXample here

    享受!!

    【讨论】:

    • 我可以在 SurfaceView 上使用它而不是 Circle 我可以更改为复杂路径吗?
    【解决方案2】:

    在过去的几周里,我只是在为一个游戏做这件事——我是如何做到的,是从触摸事件(当用户将其绘制到屏幕上时)给出的坐标中获取每个点,然后添加它到一个列表。我将该列表转换为绘制到屏幕的路径,然后让对象根据每一帧的 onDraw 方法中的列表更新其位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-26
      • 2011-09-03
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 2015-07-28
      相关资源
      最近更新 更多