2016-05-16 6 views
0

私はRectangleを10秒間に360度回転させたいと思っていました。また、5fps、10fpsな​​ど、別のフレームレートを適用したいと思います。ただし、フレームレートが何であっても、長方形は10秒で回転するはずです。アンドロイドで時間ベースのアニメーションを行うにはどうすればいいですか?

アニメーションのfpsを制御する方法を教えてください。 どのアニメーション方法を使用する必要がありますか?

私は以下の方法を使用しています。 それを行うための他の良い方法を提案してください。 ありがとうございました。

public class Square extends View { 

private Rect rect; 
private Paint paint; 
float height1; 
float width1; 

public Square(Context context) 
{ 

super(context); 
DisplayMetrics displaymetrics = new DisplayMetrics(); 
((Activity)  getContext()).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
    int height = displaymetrics.heightPixels; 
int width = displaymetrics.widthPixels; 
height1=height; 
width1=width; 

Point cos = new Point(width/2,height/2); 
int left = cos.x-(200); 
int top = cos.y - 200; 
int right =cos.x+200; 
int bottom = cos.y+200; 

rect = new Rect(left,top,right,bottom); 

// create a rectangle that we'll draw late rect = new Rect(x, y, sideLength, sideLength); 

// create the Paint and set its color 
paint = new Paint(); 






} 


protected void onDraw(final Canvas canvas) { 


super.onDraw(canvas); 
    /* canvas.drawColor(Color.BLACK); 
    canvas.drawRect(rect, paint);*/ 
    //canvas.drawColor(Color.BLACK); 
    long time1 = System.nanoTime(); 
    paint.setStyle(Paint.Style.FILL); 
paint.setColor(Color.WHITE); 
canvas.drawRect(rect, paint); 


// border 
paint.setStyle(Paint.Style.STROKE); 
paint.setColor(Color.GREEN); 
canvas.drawRect(rect, paint); 

long ti = animate().getDuration(); 
String x = "hello"; 

//Log.e("Tag",x+ti); 

long lsttime = System.nanoTime(); 
double fps = 100000000.0/(lsttime - time1); 
animate().rotation(360).setDuration(10000).start(); 


String fpss = "" + fps; 
Log.e("Tag", fpss); 
} 

} 
+0

私たちに教えてください。あなたはこれまでに何を試しましたか? –

答えて

0
ObjectAnimator rotate = ObjectAnimator.ofFloat(YOUR_LAYOUT, View.ROTATION_Y, 0.0f, 90f, 180f, 360f); 
rotate .setDuration(10000); //10sec 
rotate .setInterpolator(new AccelerateDecelerateInterpolator()); 

あなたはObjectAnimatorを使用する必要があります。インターポレーターは、アニメーションのやり方を説明し、可能な限りYouTubeを見ます。

+0

これでFPSをどのように制御できますか? –

+0

これはFPSとは関係ありません。時間ごとの変更を制御できます。 FPSは1秒あたりのフレーム数であるため、複雑なゲームのグラフィックを最適化しない限り、デフォルト値を決して変更しないでください。 –

+0

私の時間は一定です。つまり10秒です。私はそれを回転させるために矩形とアニメーション()メソッドを描画するためにキャンバスを使用しています。 –

関連する問題