アクター クラスは x と y の値で描画されるため、x と y の値を制御することでアクターの位置を変更できますが、アクターのその他の効果は Action クラスと連携して操作する必要があります。
Actionクラスは抽象クラスで、com.badlogic.gdx.scenes.scene2d.actionsパッケージ内の全ての具体的な実装を持ちます。
パッケージ内のクラスは、その機能によって2つのカテゴリに分けることができます:
1、コントロールアクション 2、パフォーマンスアクション
コントロールアクションは直接のパフォーマンス効果を持たず、ディレイなどのパフォーマンスアクションであるオブジェクトを操作します。
パフォーマンスアクションは、AnimationActionを継承し、MoveToのようなアクターを操作する直接的なパフォーマンスエフェクトです。
では、隣同士で言ってみてください:
コントロールクラス:
ディレイ
アクションの実行を秒単位で遅らせます。
フォーエバー
常に行動を実行。
パラレル
並列実行アクション。
リピート
この動作を何度も繰り返します。
シーケンス
アクションを順番に実行します。
削除 $ ()
すべてのアクションを削除します。
パフォーマンスカテゴリー
フェードイン $ フェードアウト $
フェードイン/アウト効果
フェード・トゥ
継続時間秒数がアルファ値に変更。
MoveTo $ MoveBy $
デュレーションを使用して x,y に移動します。
RotateBy $ RotateTo $.
デュレーション秒数で回転を度単位で指定します。
スケール
XをscaleXに、YをscaleYに秒単位でスケーリングします。
デモンストレーション
ひとつひとつはあまりに面倒な例を書きましたが、実際に複数のアプリケーションを組み合わせて使用すると、次のような包括的な例になります:
主人公は
点滅、飛行、回転のエフェクトは、アクションの組み合わせによって実現します。
コードは以下の通り:
package comblogs.htynkn.listener;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.FadeIn;
import com.badlogic.gdx.scenes.scene2d.actions.FadeOut;
import com.badlogic.gdx.scenes.scene2d.actions.MoveBy;
import com.badlogic.gdx.scenes.scene2d.actions.MoveTo;
import com.badlogic.gdx.scenes.scene2d.actions.Parallel;
import com.badlogic.gdx.scenes.scene2d.actions.Repeat;
import com.badlogic.gdx.scenes.scene2d.actions.RotateTo;
import com.badlogic.gdx.scenes.scene2d.actions.Sequence;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
public class FirstGame implements ApplicationListener {
private Stage stage;
private Texture texture;
@Override
public void create() {
stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
true);
texture = new Texture(Gdx.files.internal("star.png"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
float duration = 4f;
int maxwidth = Gdx.graphics.getWidth() - texture.getWidth();
int maxheight = Gdx.graphics.getHeight() - texture.getHeight();
for (int i = 0; i < 20; i++) {
Image image = new Image("star" + i, texture);
image.x = MathUtils.random(0, maxwidth);
image.y = MathUtils.random(0, Gdx.graphics.getHeight()); //ランダムに表示される
Action moveAction = Sequence.$(MoveTo.$(MathUtils.random(0,
maxwidth), MathUtils.random(0, maxheight), duration / 2),
MoveBy.$(MathUtils.random(0, maxwidth), MathUtils.random(0,
maxheight), duration / 2)); //移動方向と位置のランダム化
Action rotateAction = RotateTo.$(360, duration); //回転
Action fadeAction = Repeat.$(Sequence.$(FadeOut.$(duration / 20),
FadeIn.$(duration / 20)), 10); //点滅を10回繰り返す
image.action(Parallel.$(moveAction, rotateAction, fadeAction)); //すべてのアクションを並列に行う
stage.addActor(image);
}
Gdx.input.setInputProcessor(stage);
}
@Override
public void dispose() {
texture.dispose();
stage.dispose();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
}
実際、各アクションの使い方は非常にシンプルで、主な問題は、ニーズに合った効果を表示するために、どのように組み合わせ、アレンジするかということです。
libgdxは毎日何バージョンも更新されていて、普段は更新が早くないことに気づきました。ファイル経由でUIスタイルを設定するものは私にとって非常に興味深いものですが、仕様には多くの問題があります。




