4

我正在尝试使用动作来缩放我的演员。但它不起作用。我只希望我的演员在给定的时间内增加/减少它的大小。

Actor 只会等待我给出的 2 秒持续时间ScaleTo。它会根据MoveTo我给它的动作正确移动。

public class SpriteTest extends Actor {
       private Sprite sprite;
       private TextureAtlas atlas;
       Rectangle boundsd = new Rectangle();

       public SpriteTest(FirstGame game) {
           //super(game);
           Gdx.app.log( FirstGame.LOG, "spritetest's costructor" );
           atlas = new TextureAtlas(Gdx.files.internal("pages-info.atlas"));
           sprite = atlas.createSprite("Plus");
       }

       public void draw(SpriteBatch batch,float parentAlpha) {
            batch.draw(sprite, x, y);
       }

// We are adding the actor to the stage in another class

public class LevelScreen extends AbstractScreen {
   private Jumper2D jumper2d;
   SpriteTest obstacled = new SpriteTest(game); 

   public LevelScreen(FirstGame game) {
      super(game);
   }

   @Override
   protected boolean isGameScreen() {
      return true;
   }  

   @Override
   public void show() {
      super.show();

      stage.addActor(obstacled); 
      obstacled.action  
      (Forever.$
            (Sequence.$
               (ScaleTo.$(1.4f, 1.4f, 2),(MoveTo.$(100,120, 3f) ))
                         ));
      jumper2d = Jumper2D.create(getAtlas());
      stage.addActor(jumper2d);
      stage.draw();
   }

   public void render () {
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
      stage.draw();
   }
}

任何帮助表示赞赏

4

1 回答 1

8

您的draw()方法SpriteTest是忽略Actor. 您需要适当地绘制缩放/旋转/大小的精灵。(您可能还需要设置 Actor 的 x、y、宽度和高度 --- 参见 setBounds

public void draw(SpriteBatch batch, float parentAlpha)
{
     final Color c = getColor();
     batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
     batch.draw(sprite, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
于 2013-02-28T16:45:30.710 回答