<small id='s0QCw'></small><noframes id='s0QCw'>

  • <tfoot id='s0QCw'></tfoot>

  • <i id='s0QCw'><tr id='s0QCw'><dt id='s0QCw'><q id='s0QCw'><span id='s0QCw'><b id='s0QCw'><form id='s0QCw'><ins id='s0QCw'></ins><ul id='s0QCw'></ul><sub id='s0QCw'></sub></form><legend id='s0QCw'></legend><bdo id='s0QCw'><pre id='s0QCw'><center id='s0QCw'></center></pre></bdo></b><th id='s0QCw'></th></span></q></dt></tr></i><div id='s0QCw'><tfoot id='s0QCw'></tfoot><dl id='s0QCw'><fieldset id='s0QCw'></fieldset></dl></div>

    <legend id='s0QCw'><style id='s0QCw'><dir id='s0QCw'><q id='s0QCw'></q></dir></style></legend>

          <bdo id='s0QCw'></bdo><ul id='s0QCw'></ul>
      1. Libgdx 动画不起作用

        时间:2023-05-20
        • <tfoot id='MJb1o'></tfoot>

                <bdo id='MJb1o'></bdo><ul id='MJb1o'></ul>
              • <small id='MJb1o'></small><noframes id='MJb1o'>

                  <legend id='MJb1o'><style id='MJb1o'><dir id='MJb1o'><q id='MJb1o'></q></dir></style></legend>

                  <i id='MJb1o'><tr id='MJb1o'><dt id='MJb1o'><q id='MJb1o'><span id='MJb1o'><b id='MJb1o'><form id='MJb1o'><ins id='MJb1o'></ins><ul id='MJb1o'></ul><sub id='MJb1o'></sub></form><legend id='MJb1o'></legend><bdo id='MJb1o'><pre id='MJb1o'><center id='MJb1o'></center></pre></bdo></b><th id='MJb1o'></th></span></q></dt></tr></i><div id='MJb1o'><tfoot id='MJb1o'></tfoot><dl id='MJb1o'><fieldset id='MJb1o'></fieldset></dl></div>
                    <tbody id='MJb1o'></tbody>
                  本文介绍了Libgdx 动画不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我一直在阅读有关 libgdx 的内容,但一直被这个动画问题困扰.我从他们的 github 阅读了有关 libgdx 中的动画,当我在手机上运行我的应用程序时,应用程序在加载屏幕后崩溃.这是从 Actor 扩展而来的我的玩家 Actor.我在我的菜单屏幕类中创建玩家演员并将其添加到舞台.假设在菜单屏幕中出现上下飞行,但应用程序崩溃.我知道这是我的玩家演员,因为当我在菜单屏幕类中注释掉玩家演员时,应用程序不会崩溃.我在我的平面精灵上使用纹理打包器并将其加载到我的游戏中.

                  I have been reading about libgdx and I have been stuck on this animation problem. I have reading about animation in libgdx from their github and when I run my app on my phone, the app crashes after the loading screen. Here is my player Actor that extends from Actor. I create the player actor in my menu screen class and add it to the stage. It is suppose to appear flying up and down in the menu screen but the app crashes. I know it is my player actor because when I comment out the player actor in my menu screen class the app does not crash. I use texture packer on my plane sprite and load it into my game.

                  public class PlayerActor extends Actor{
                  
                  private DrunkPilot pGame;
                  
                  private static final int NUM_ROWS = 5, NUM_COLS = 5;
                  
                  private Animation<TextureRegion> drunkFlying;
                  private float stateTimer;
                  private TextureRegion region;
                  private Texture planeTex;
                  
                  public PlayerActor(){
                  
                      planeTex = pGame.assetManager.manager.get(Constants.plane);
                      planeTex = new Texture(Gdx.files.internal(Constants.plane));
                  
                      drunkFlyingAnimation();
                  
                  }
                  
                  private void drunkFlyingAnimation(){
                  
                      TextureRegion[][] tmp = TextureRegion.split(planeTex, planeTex.getWidth() / NUM_COLS, planeTex.getHeight() / NUM_ROWS);
                      TextureRegion[] flyFrames = new TextureRegion[NUM_COLS * NUM_ROWS];
                  
                      int index = 0;
                      for (int i = 0; i < NUM_ROWS; i++) {
                          for (int j = 0; j < NUM_COLS; j++) {
                              flyFrames[index++] = tmp[i][j];
                          }
                      }
                  
                      drunkFlying = new Animation<TextureRegion>(0.025f, flyFrames);
                      stateTimer = 0;
                      region = drunkFlying.getKeyFrame(0);
                  }
                  
                  @Override
                  public void draw(Batch batch, float alpha){
                      super.draw(batch, alpha);
                      GdxUtils.clearScreen();
                      stateTimer += Gdx.graphics.getDeltaTime();
                      TextureRegion drunk = drunkFlying.getKeyFrame(stateTimer, true);
                  
                      batch.draw(drunk, getX(), getY(), getWidth() / 2, getHeight() / 2, getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
                  
                  }
                  
                  public void dispose(){
                      planeTex.dispose();
                  }
                  

                  }

                  这是我将我的演员添加到舞台的地方.

                  Here is where I add my actor to the stage.

                  @Override
                  public void show() {
                      Gdx.input.setInputProcessor(menuStage);
                  
                      menuTitle = new Image(menuTitleTexture);
                      menuStartImg = new Image(menuStartTexture);
                  
                      menuTable = new Table();
                      menuTable.setFillParent(true);
                      menuTable.add(menuTitle).pad(20).align(Align.top);
                      menuTable.row();
                      menuTable.add(menuStartImg).align(Align.bottom).pad(30);
                  
                      menuStage.addActor(parallaxBackground);
                      menuStage.addActor(menuTable);
                      menuStage.addActor(player);
                  }
                  

                  推荐答案

                  当您使用 TexturePacker 时,有一种更简单的方法来创建动画.

                  When you use TexturePacker there is an easier way to create animations.

                  当我们想要创建跑步动画时
                  首先,您将所有动画图像添加到 TexturePacker,您必须查看每一帧都有相同的名称 + 下划线 + frameNumber.所以帧的名称必须是:run_1、run_2、run_3 等.

                  When we want to create a run animation
                  First you ad all animation images to TexturePacker you have to look that every frame has the same name + underscore + frameNumber. So the name of the frames must be: run_1, run_2, run_3 etc.

                  当我们创建它时,我们的资产中有一个 run.txt 和 run.png.

                  When we created it we have a run.txt and run.png in our assets.

                  现在我们可以使用 AssetManager 加载 TextureAtlas:

                  Now we can load the TextureAtlas with our AssetManager:

                  AssetManager assetManager = new AssetManager();
                  assetManager.load("run.txt", TextureAtlas.class);
                  assetManager.finishLoading();
                  TextureAtlas runAnimationAtlas = assetManager.get("run.txt", TextureAtlas.class);
                  

                  有了这个 TextureAtlas,我们可以创建我们的动画:

                  With this TextureAtlas we can create our Animation:

                  float frameDuration = 0.1f; // the duration between the animation frames
                  Animation<TextureRegion> runAnimation = new Animation<TextureRegion>(frameDuration, runAnimationAtlas.findRegions("run"), Animation.PlayMode.LOOP);
                  

                  并渲染动画:

                  batch.draw(runAnimation.getKeyFrame(stateTimer),posX, posY)
                  

                  这篇关于Libgdx 动画不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:文本字段 libgdx 中的字体大小 下一篇:Google Play 游戏服务无法登录

                  相关文章

                  最新文章

                    <bdo id='dlsba'></bdo><ul id='dlsba'></ul>
                  1. <small id='dlsba'></small><noframes id='dlsba'>

                    <legend id='dlsba'><style id='dlsba'><dir id='dlsba'><q id='dlsba'></q></dir></style></legend>
                  2. <i id='dlsba'><tr id='dlsba'><dt id='dlsba'><q id='dlsba'><span id='dlsba'><b id='dlsba'><form id='dlsba'><ins id='dlsba'></ins><ul id='dlsba'></ul><sub id='dlsba'></sub></form><legend id='dlsba'></legend><bdo id='dlsba'><pre id='dlsba'><center id='dlsba'></center></pre></bdo></b><th id='dlsba'></th></span></q></dt></tr></i><div id='dlsba'><tfoot id='dlsba'></tfoot><dl id='dlsba'><fieldset id='dlsba'></fieldset></dl></div>

                    1. <tfoot id='dlsba'></tfoot>