使用OpenGL ES 2.0绘制动画圆圈

时间:2014-08-16 07:58:29

标签: android opengl-es opengl-es-2.0 android-animation

我有一个用OpenGL顶点创建的圆形对象。

当触摸圆圈时,我想要激活缩放动画。圆半径将变大,直到达到一定半径,然后圆将变换回原始半径。

实现此动画的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

你有几种可能性。最简单的方法是创建一个变量,该变量将保存圆的缩放因子,并在渲染之前将所有顶点乘以它。然后使用一些计时器并及时调整缩放系数,您可以创建动画。 我应该补充一点,如果你想通过它的中心来缩放你的圆,那么你必须首先平移圆顶点,使圆的中心位于(0,0)点,然后按因子缩放并将圆转换回其初始值位置。

如果您尝试实现的圆形动画是某种GUI元素,那么我想到的另一种方式是:

  1. 在xml中创建一个ImageView或在代码中动态创建

  2. 在其上绘制顶点

  3. 创建一个XML android动画并随时应用

  4. 以下是在ImageView上绘制圆圈的代码草稿:

    Bitmap tempBitmap = Bitmap.createBitmap(yourCircleWidth, yourCircleHeight, Bitmap.Config.ARGB_8888);
                    Canvas tempCanvas = new Canvas(tempBitmap);
    
                    //Draw the circle into the canvas               
                    tempCanvas.drawColor(Color.WHITE);
                    Paint paint = new Paint();
                    paint.setStyle(Paint.Style.FILL);
                    tempCanvas.drawCircle(circleCenterX, circleCenterY, yourCircleRadius, paint);
    
                //Attach the canvas to the ImageView
                yourImageView.setImageDrawable(new BitmapDrawable(yourImageView.getResources(), tempBitmap));
    

    对于XML动画,这里有一个很好的参考: http://www.androidhive.info/2013/06/android-working-with-xml-animations/

相关问题