Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. public class MainButtons {
  2. public Viewport viewport;
  3. public Stage stage;
  4. public boolean centerPressed;
  5.  
  6. public Image fire;
  7. public Image center;
  8. public Sound flap;
  9.  
  10. public OrthographicCamera camera;
  11. public static Table table;
  12.  
  13.  
  14. //Constructor.
  15. public MainButtons(SpriteBatch spriteBatch) {
  16. camera = new OrthographicCamera();
  17. viewport = new StretchViewport(KidTele.V_WIDTH,KidTele.V_HIEGH,camera);
  18. stage = new Stage(viewport, spriteBatch);
  19. //InputMultiplexer this is why only input handling from controller
  20. flap= Gdx.audio.newSound(Gdx.files.internal("one.mp3"));
  21. Gdx.input.setInputProcessor(stage);
  22.  
  23. fire= new Image(new Texture("cars/fire.png"));
  24.  
  25. //buttonone.setSize(10, 5);
  26.  
  27.  
  28. menuTable();
  29. defineCenter();
  30.  
  31. }
  32. public void defineCenter()
  33. {
  34. center=new Image(new Texture(Gdx.files.internal("0.png")));
  35.  
  36. center.setBounds(viewport.getWorldWidth() / 5f, viewport.getWorldHeight() / 3f, viewport.getWorldWidth() / 1.5f, viewport.getWorldHeight() / 3f);
  37. center.addListener(new InputListener() {
  38. @Override
  39. public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
  40. centerPressed = true;
  41. return true;
  42. }
  43.  
  44. @Override
  45. public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
  46. //center.setOrigin(center.getWidth()/2,center.getHeight()/2);
  47. //center.addAction(Actions.sequence(Actions.rotateTo(360, 2), Actions.fadeIn(1)));
  48. center.addAction(Actions.sequence(Actions.fadeOut(1), Actions.fadeIn(1)));
  49. centerPressed = false;
  50. }
  51. });
  52. //center.setVisible(false);
  53. stage.addActor(center);
  54. }
  55. public void draw() {
  56. stage.draw();
  57. }
  58. public void resize(int width, int height) {
  59. viewport.update(width, height);
  60. }
  61. }
  62.  
  63. public class PlayScreen implements Screen {
  64. private KidTele game;
  65. private OrthographicCamera gamecam;
  66. private Viewport gameport;
  67. private World world;
  68. private Box2DDebugRenderer b2dr;
  69. private MainButtons mainButtons;
  70. private Texture background;
  71. private Sound flap;
  72. public PlayScreen(KidTele game)
  73. {
  74. this.game=game;
  75. gamecam=new OrthographicCamera();
  76. gameport=new StretchViewport(KidTele.V_WIDTH,KidTele.V_HIEGH,gamecam);
  77. //stage=new Stage(gameport,((KidTele) game).batch);
  78. background=new Texture("background2.png");
  79. gamecam.position.set(gameport.getWorldWidth()/2f,gameport.getWorldHeight()/2f,0);
  80. b2dr=new Box2DDebugRenderer();
  81. world=new World(new Vector2(0,0.8f),true);
  82. flap= Gdx.audio.newSound(Gdx.files.internal("one.mp3"));
  83. mainButtons=new MainButtons(game.batch);
  84. }
  85. @Override
  86. public void show() {
  87.  
  88. }
  89. public void handleinput(float dt)
  90. {
  91.  
  92. if(Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
  93. mainButtons.stopMusic();
  94. game.setScreen(new PlayScreen(game));
  95. }
  96.  
  97. }
  98. public void update(float dt)
  99. {
  100. handleinput(dt);
  101. world.step(1 /60f, 6, 2);
  102. //player.update(dt);
  103.  
  104. gamecam.update();
  105. }
  106.  
  107. @Override
  108. public void render(float delta) {
  109.  
  110. update(delta);
  111. Gdx.gl.glClearColor(1, 1, 1, 1);
  112. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  113.  
  114. b2dr.render(world, gamecam.combined);
  115. game.batch.setProjectionMatrix(gamecam.combined);
  116.  
  117. game.batch.begin();
  118.  
  119. game.batch.draw(background, 0, 0, gameport.getWorldWidth(), gameport.getWorldHeight());
  120. game.batch.end();
  121. mainButtons.stage.act();
  122. mainButtons.stage.draw();
  123. mainButtons.draw();
  124. }
  125.  
  126. @Override
  127. public void resize(int width, int height) {
  128. gameport.update(width, height);
  129. mainButtons.resize(width, height);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement