LoginSignup
10
10

More than 5 years have passed since last update.

Android TextureView、SurfaceViewで簡単にアニメーション 〜FPSAnimator〜

Last updated at Posted at 2016-02-13

FPSAnimator

TextureViewまたは、SurfaceViewで簡単にアニメーションが作成できるライブラリです。
Bitmap描画、Text描画、直接Canvasにカスタマイズしたものをアニメーションさせることも可能です。
Tweenアニメーション、放物線運動、スプライトシートアニメーションが簡単に作成できます。
特徴として、FPSの制御も可能です。アニメーション以外にも多くのViewの更新等がある際には少しFPSを下げる等をして全体のバランスをとることが可能になります。

FPSAnimator

基本的な使い方

Gradleの設定

    dependencies {
        // jCenter
        compile 'com.daasuu:FPSAnimator:0.2.2'
    }

FPSTextureViewをレイアウトに設定。attributeにFPSを設定。SurfaceViewを使用の際はFPSSurfaceView
を使用してください。
デフォルトのFPSは30で設定されています。

    <com.daasuu.library.FPSTextureView
        android:id="@+id/animation_texture_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:FPSAnimator_fps="24"
        />

ActivityのonCreate、FragmentのonCreateViewでbindします。

    private FPSTextureView mFPSTextureView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_easing_sample);
        mFPSTextureView = (FPSTextureView) findViewById(R.id.animation_texture_view);
    }

DisplayObjectを作成し、それをFPSTextureViewにadd。tickStartの関数をたたき、アニメーション開始
されます。なお、tickStartを行うタイミングはonResumeでtickStart、onPauseでtickStopが推奨されています。

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    DisplayObject bitmapDisplay = new DisplayObject();
    bitmapDisplay
            .with(new BitmapDrawer(bitmap))
            .tween()
            .toX(1600, windowWidth - bitmap.getWidth(), Ease.BACK_IN_OUT)
            .waitTime(1000)
            .alpha(1000, 0f)
            .alpha(1000, 1f)
            .end();

    mFPSTextureView
                .addChild(bitmapDisplay)
                .tickStart();

上記のようなアニメーションが作成されます。
1.6秒で画面横までいき、1秒静止。
1秒で透明になり、1秒で透明が1に戻る。
CreatejsのTweenに似ていますね。

他にもSpriteSheetアニメーションや、放物線運動のClassも簡単に実現可能です。
他2つに関してはまた別の記事で書かせていただきます。

ぜひ、libraryにgithubのStarをお願いします。
FPSAnimator

追記:
Tweenアニメーションの詳細はこちら
SpriteSheetアニメーションの詳細はこちら
放物線運動アニメーションの詳細はこちら

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10