当我创建一个舞台时,它不允许我在libgdx中绘制精灵

7y4bm7vi  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(238)

我在libgdx做了一个游戏,海龟必须收集海星,但我使用的是演员,所以我不得不使用舞台。在创建了一个舞台之后,我无法在屏幕上绘制精灵,这也会使游戏崩溃
编辑:我忘了把batch.end()放在末尾,但它仍然没有绘制精灵
这是我的密码

  1. @Override
  2. public void render()
  3. {
  4. for (int i=0; i<5; i++)
  5. {
  6. if (Gdx.input.isTouched(i))
  7. {
  8. Vector3 touchPos = new Vector3(Gdx.input.getX(i), Gdx.input.getY(i), 0);
  9. camera.unproject(touchPos);
  10. Rectangle touch = new Rectangle(touchPos.x-16, touchPos.y-16, 32, 32);
  11. if (touch.overlaps(leftButton))
  12. {
  13. moveX-=Gdx.graphics.getDeltaTime()*80;
  14. System.out.println("left touched");
  15. }
  16. if (touch.overlaps(rightButton))
  17. {
  18. moveX+=Gdx.graphics.getDeltaTime()*80;
  19. System.out.println("right touched");
  20. }
  21. if (touch.overlaps(jumpButton))
  22. {
  23. moveY+=Gdx.graphics.getDeltaTime()*80;
  24. System.out.println("up touched");
  25. }
  26. }
  27. }
  28. // check user input
  29. mainStage.act(1/60f);
  30. // check win condition: turtle must be overlapping starfish
  31. if (turtle.overlaps(starfish))
  32. {
  33. starfish.remove();
  34. winMessage.setVisible(true);
  35. }
  36. // clear screen
  37. Gdx.gl.glClearColor(0,0,0, 1);
  38. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  39. // draw graphics
  40. mainStage.draw();
  41. batch.setProjectionMatrix(camera.combined);
  42. batch.begin();
  43. leftSpriteButton.draw(batch);
  44. rightSpriteButton.draw(batch);
  45. jumpSpriteButton.draw(batch);
  46. }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题