【问题标题】:How to change Sprite texture to Animation如何将 Sprite 纹理更改为动画
【发布时间】:2015-06-11 07:47:31
【问题描述】:

我有一个每秒生成的精灵,我不想做的是将精灵纹理更改为动画,当它被触摸时它将恢复为正常纹理。

     public void draw(SpriteBatch batch){
       enemyIterator=enemies.iterator();  //arraylist iterator
       boolean touched=Gdx.input.justTouched();
       float touchX=Gdx.input.getX();

   //rendering and making the current sprite move
       while(enemyIterator.hasNext()){
           Sprite sprite=enemyIterator.next();
           sprite.draw(batch);
           sprite.translateY(deltaTime*movement);

//detecting if the screen is touched and if the inputX is inside of the sprite.
           if(touched==true && touchX > sprite.getX() && touchX < sprite.getX()+sprite.getWidth()){
               enemyIterator.remove(); //removing the sprite when touched.
               Pools.free(sprite); //freeing the Pools
           }
       }

【问题讨论】:

    标签: java animation libgdx sprite


    【解决方案1】:

    从纹理变为动画

    创建一个名为 MySprite 的 Sprite 子类,并覆盖 draw(batch) 方法。

    在覆盖的draw方法中,如果你想绘制纹理,只需调用super.draw(batch),也可以使用你的动画绘制代码。您可以使用Gdx.graphics.getDeltaTime()获取增量时间

    为什么必须指定 timePassed

    你的程序会以与动画不同的帧率运行,所以通过告诉动画已经过去了多少时间,它可以根据自己的帧率计算出它应该在哪一帧。

    请注意,您的应用的帧速率可能因帧而异,具体取决于它需要完成的工作量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-04
      • 1970-01-01
      • 2020-04-28
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多