2016-01-07 13 views
5

私は4日前のような質問をしました。いくつかの助けを得て、私のコードは次のようになりますアクションをループできません。 libGDX

ColorAction actionBtG = new ColorAction(); 
ColorAction actionGtB = new ColorAction(); 
SequenceAction sequenceAction; 
RepeatAction repeatAction = new RepeatAction(); 
ShapeRenderer shapeRenderer; 
Color blue = new Color(Color.BLUE); 

@Override 
public void create() { 

    shapeRenderer = new ShapeRenderer(); 
    actionBtG.setColor(blue); 
    actionBtG.setEndColor(Color.GOLD); 
    actionBtG.setDuration(5); 

    actionGtB.setColor(blue); 
    actionGtB.setEndColor(Color.BLUE); 
    actionGtB.setDuration(5); 
    sequenceAction = new sequenceAction(actionBtG,actionGtB); 






    repeatAction = new RepeatAction():   
    repeatAction.setAction(sequenceAction); 
    repeatAction.setCount(RepeatAction.FOREVER); 
} 

@Override 
public void render() { 

    repeatAction.act(Gdx.graphics.getDeltaTime()); 
    Gdx.gl.glClearColor(1,1,1,1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); 
    shapeRenderer.setColor(blue); 
    shapeRenderer.rect(100, 100, 40, 40); 
    shapeRenderer.end(); 


} 

しかし、それでも間違っています。一度行動して停止する。私はそれをループする必要があるとき。青から金、金から青まで。 私はlibGDXを学んでいるので、本当に助けていただければ幸いです。ありがとう。

私は答えのすべてを読み、私のコードを編集し、それはまだdoesntの仕事をしている:

ここ
private Actor actionManager = new Actor(); 
ColorAction actionBtG = new ColorAction(); 
ColorAction actionGtB = new ColorAction(); 
SequenceAction sequenceAction; 
RepeatAction repeatAction; 
Color activeColor = new Color(Color.BLUE); 
ShapeRenderer shapeRenderer; 


@Override 
public void create() { 

    shapeRenderer = new ShapeRenderer(); 
    actionBtG.setColor(activeColor); 
    actionBtG.setEndColor(Color.GOLD); 
    actionBtG.setDuration(5); 

    actionGtB.setColor(activeColor); 
    actionGtB.setEndColor(Color.BLUE); 
    actionGtB.setDuration(5); 
    sequenceAction = new SequenceAction(actionBtG,actionGtB); 
    repeatAction = new RepeatAction(); 
    repeatAction.setAction(sequenceAction); 
    repeatAction.setCount(RepeatAction.FOREVER); 

    actionManager.addAction(repeatAction); 
} 

は、それが色を変えていない今

@Override 
    public void render() { 
    Gdx.gl.glClearColor(1, 1, 1, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
    actionManager.act(Gdx.graphics.getDeltaTime()); 

    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); 
    shapeRenderer.setColor(blue); 
    shapeRenderer.rect(100, 100, 40, 40); 
    shapeRenderer.end(); 
} 

)(レンダリングされ、それはいつもです青。

+1

ターゲット](https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/Action.html#setTarget-com.badlo gic.gdx.scenes.scene2d.Actor-)の「アクション」? – asherbar

+0

@ user2016436 ColorActionsは 'setColor'を使うとターゲットを必要としません。 – Tenfour04

+0

青色のままにするつもりはないので、青色の名前を変更することをお勧めします。 – Tenfour04

答えて

3

アクターに使用される予定のアクションに関するバグがあります。多くのアクションはアクタなしでうまく動作しますが、SequenceActionはアクタにアタッチされてまだ実行中であるかどうかを検出するため、動作しません。

これを設定すると、トップレベルのアクションにダミーのアクタを追加するのがやや難解な方法です。これは、ステージ内のアクタにアクションを追加するときの動作をシミュレートします。

repeatAction.setActor(new Actor()); 

アプリでより多くのアクションを使用する場合、あなたはすべてのあなたの行動を管理するために使用する単一俳優作成することができます:あなたが使用したい場合は、

private Actor actionManager = new Actor(); 

//when creating actions: 
actionManager.addAction(repeatAction); 

//In render(), use this instead of calling act on individual actions 
//It will call act on all actions in the actor: 
actionManager.act(Gdx.graphics.getDeltaTime()); 

そしてもちろんのは、作図用のステージでは、アクションマネージャとしてアクタを使用する代わりに、単にステージにアクションを追加することができます。

私は個人的にシーン2を見つけます。アクションは、UniversalTweenEngineよりも使いやすくセットアップする必要があります。

+0

私はまた、libgdxアクションはUniversal Tween Engineよりもセットアップが簡単だと思っていますが、あなたのゲームオブジェクトがすべてのlibgdxアクターではない場合、他の選択肢はありますか?最終的には、おそらく、libgdxアクションでトゥイーンできないものをトゥイーンしたいと思うでしょう。大きなプロジェクトでは、Universal Tween Engineを使いたいと思われます。 – Barodapride

+0

@ Tenfour04はUの答えの後半に言ったように、質問にいくつかの情報を追加しました。 – WardS

+0

それは動作します、どのように分かっていませんが、それは動作します。私はちょうど新しいプロジェクトを作成し、コードを手書きで書くことなく、コードを手書きで書くことができました。 ありがとうございます。 – WardS

0

LibgdxアクションはLibgdxアクターのみです。あなたはアクションを作成していますが、それをアクタに割り当てていません。作成したアクションを無視して、shapeRendererの色を青色に設定するだけです。時間をかけて色を変更したい場合は、Universal tween engineからトゥイーンを使用することをお勧めします。

また、shapeRendererを削除し、Image(Actorのサブクラス)を使用することもできます。次に、あなたのアクションをイメージに割り当てます。しかし、これを行うには、ステージを作成してステージにイメージを追加する必要があります。 scene2d wikiを参照してください。

いずれの方法でもいくつかの追加手順があります。おそらくこれは、簡単に作業を取得するために安価なハックは以下のようになります。

  1. だけで画像を作成した:i =新しいイメージ()

    イメージ。

  2. は、画像I

    i.addAction(repeatAction)にあなたのアクションを割り当てます。

  3. i.actでrepeatAction.act(...)を置き換える(Gdx.graphics.getDeltaTime());

    shapeRenderer.setColor(i.getColor())に

  4. 変化shapeRenderer.setColor(青)

希望します。

+1

実際には、カラーアクションは 'blue' Colorインスタンスをターゲットにしているので、シェイプレンダラーは実際にアクションから正しいカラー値を読み取っています。 – Tenfour04

+0

私が興味深いのは、俳優に関連しない行動をすることができるということです。それは本当に便利ですね。私はそれを知らなかった。ここでは、実行可能な遅延アクションを全面的に使用するつもりです。 – Barodapride

+0

私はそれがColorActionに特有だと思います。私の他の答えを見てください。ダミーアクタをアクションマネージャとして使用できます。 – Tenfour04

0

したがって、次のサンプルは、(無限回転)私のために働いた

方法1:(推奨)

loadingActor.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.rotateBy(360, 1))); 

方法2:んあなたは[セット

Image loadingActor = new Image(AssetsController.getInstance().getLoading()); 
loadingActor.setOrigin(Align.center); 
final SequenceAction infiniteRotate = Actions.sequence(); 
infiniteRotate.addAction(Actions.rotateTo(0 , 0f)); 
infiniteRotate.addAction(Actions.rotateTo(360 , 1f)); 
loadingActor.addAction(Actions.forever(infiniteRotate)); 
関連する問題