Advertisement
Guest User

lingdx button test

a guest
Nov 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.97 KB | None | 0 0
  1. package com.marsminer.game;
  2.  
  3. import com.badlogic.gdx.ApplicationAdapter;
  4. import com.badlogic.gdx.Game;
  5. import com.badlogic.gdx.Gdx;
  6. import com.badlogic.gdx.assets.AssetManager;
  7. import com.badlogic.gdx.graphics.GL20;
  8. import com.badlogic.gdx.graphics.Texture;
  9. import com.badlogic.gdx.graphics.g2d.Batch;
  10. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  11. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  12. import com.badlogic.gdx.graphics.g2d.TextureAtlas;
  13. import com.badlogic.gdx.scenes.scene2d.Stage;
  14. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  15. import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
  16.  
  17. import java.awt.Color;
  18.  
  19. import sun.applet.Main;
  20.  
  21. public class MarsMiner extends Game {
  22.     Stage stage;
  23.     TextButton button;
  24.     TextButton.TextButtonStyle textButtonStyle;
  25.     BitmapFont font;
  26.     Skin skin;
  27.     TextureAtlas textureAtlas;
  28.    
  29.     @Override
  30.     public void create () {
  31.         stage = new Stage();
  32.         Gdx.input.setInputProcessor(stage);
  33.         font = new BitmapFont();
  34.         skin = new Skin();
  35.         textureAtlas = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack"));
  36.         skin.addRegions(textureAtlas);
  37.         textButtonStyle = new TextButton.TextButtonStyle();
  38.         textButtonStyle.font = font;
  39.         textButtonStyle.up = skin.getDrawable("up-button");
  40.         textButtonStyle.down = skin.getDrawable("down-button");
  41.         textButtonStyle.checked = skin.getDrawable("checked-button");
  42.         button = new TextButton("Button1", textButtonStyle);
  43.         stage.addActor(button);
  44.  
  45.     }
  46.  
  47.     @Override
  48.     public void render () {
  49.         Gdx.gl.glClearColor(1, 0, 0, 1);
  50.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  51.         super.render();
  52.         stage.draw();
  53.     }
  54. }
  55.  
  56. Output:
  57.  
  58. package com.marsminer.game;
  59.  
  60. import com.badlogic.gdx.ApplicationAdapter;
  61. import com.badlogic.gdx.Game;
  62. import com.badlogic.gdx.Gdx;
  63. import com.badlogic.gdx.assets.AssetManager;
  64. import com.badlogic.gdx.graphics.GL20;
  65. import com.badlogic.gdx.graphics.Texture;
  66. import com.badlogic.gdx.graphics.g2d.Batch;
  67. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  68. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  69. import com.badlogic.gdx.graphics.g2d.TextureAtlas;
  70. import com.badlogic.gdx.scenes.scene2d.Stage;
  71. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  72. import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
  73.  
  74. import java.awt.Color;
  75.  
  76. import sun.applet.Main;
  77.  
  78. public class MarsMiner extends Game {
  79.     Stage stage;
  80.     TextButton button;
  81.     TextButton.TextButtonStyle textButtonStyle;
  82.     BitmapFont font;
  83.     Skin skin;
  84.     TextureAtlas textureAtlas;
  85.    
  86.     @Override
  87.     public void create () {
  88.         stage = new Stage();
  89.         Gdx.input.setInputProcessor(stage);
  90.         font = new BitmapFont();
  91.         skin = new Skin();
  92.         textureAtlas = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack"));
  93.         skin.addRegions(textureAtlas);
  94.         textButtonStyle = new TextButton.TextButtonStyle();
  95.         textButtonStyle.font = font;
  96.         textButtonStyle.up = skin.getDrawable("up-button");
  97.         textButtonStyle.down = skin.getDrawable("down-button");
  98.         textButtonStyle.checked = skin.getDrawable("checked-button");
  99.         button = new TextButton("Button1", textButtonStyle);
  100.         stage.addActor(button);
  101.  
  102.     }
  103.  
  104.     @Override
  105.     public void render () {
  106.         Gdx.gl.glClearColor(1, 0, 0, 1);
  107.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  108.         super.render();
  109.         stage.draw();
  110.     }
  111. }
  112.  
  113. Output:
  114.  
  115. Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: File not found: buttons\buttons.pack (Internal)
  116.     at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
  117.     at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
  118.     at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
  119.     at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
  120.     at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
  121.     at com.marsminer.game.MarsMiner.create(MarsMiner.java:35)
  122.     at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
  123.     at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement