Advertisement
Guest User

menuscreen

a guest
Sep 18th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. package tk.tharline.minefinder.screen;
  2. import tk.tharline.minefinder.*;
  3.  
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.Screen;
  6. import com.badlogic.gdx.graphics.GL20;
  7. import com.badlogic.gdx.graphics.Texture;
  8. import com.badlogic.gdx.graphics.Texture.TextureFilter;
  9. import com.badlogic.gdx.graphics.g2d.Sprite;
  10. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  11. import com.badlogic.gdx.graphics.g2d.TextureAtlas;
  12. import com.badlogic.gdx.scenes.scene2d.InputEvent;
  13. import com.badlogic.gdx.scenes.scene2d.InputListener;
  14. import com.badlogic.gdx.scenes.scene2d.Stage;
  15. import com.badlogic.gdx.scenes.scene2d.ui.Image;
  16. import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
  17. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  18.  
  19. public class MenuScreen implements Screen{
  20.     private MineFinder game;
  21.     private Stage stage;
  22.     private TextureAtlas atlas;
  23.     private Skin skin;
  24.     private SpriteBatch batch;
  25.     private ImageButton button;
  26.     private Texture background;
  27.     private Image asd;
  28.     private Sprite bg;
  29.    
  30.     public MenuScreen(MineFinder game){
  31.         this.game = game;
  32.     }
  33.  
  34.     @Override
  35.     public void render(float delta) {
  36.         Gdx.gl.glClearColor(0, 0, 0, 1);
  37.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  38.        
  39.         stage.act(delta);
  40.        
  41.         batch.begin();
  42.         stage.draw();
  43.         batch.end();
  44.        
  45.     }
  46.  
  47.     @Override
  48.     public void resize(int width, int height) {
  49.         if(stage == null){
  50.             stage = new Stage(width, height, true);
  51.         }
  52.         stage.clear();
  53.        
  54.         Gdx.input.setInputProcessor(stage);
  55.        
  56.         background = new Texture(Gdx.files.internal("data/pali/mine-start.jpg"));
  57.         bg = new Sprite(background);
  58.         background.setFilter(TextureFilter.Linear, TextureFilter.Linear);
  59.        
  60.         asd = new Image(bg);
  61.         asd.setX(0);
  62.         asd.setY(0);
  63.        
  64.         button = new ImageButton(skin.getDrawable("on_start"), skin.getDrawable("on_start_two"));
  65.         button.setColor(1, 1, 1, 1);
  66.         button.setX(Gdx.graphics.getWidth() / 2 - button.getWidth() / 2);
  67.         button.setY(Gdx.graphics.getHeight() / 2 - button.getHeight() / 2 - 130);
  68.        
  69.         button.addListener(new InputListener(){
  70.             @Override
  71.             public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
  72.                 return true;
  73.             }
  74.             @Override
  75.             public void touchUp(InputEvent event, float x, float y, int pointer, int button){
  76.                 MineFinder.Log.debug("xpos: " + x + ", ypos: " + y);
  77.                 game.setScreen(new GameScreen(game));
  78.             }
  79.         });
  80.         stage.addActor(asd);
  81.         stage.addActor(button);
  82.     }
  83.  
  84.     @Override
  85.     public void show() {
  86.         batch = new SpriteBatch();
  87.         atlas = new TextureAtlas("data/buttons.pack");
  88.         skin = new Skin();
  89.         skin.addRegions(atlas);
  90.     }
  91.  
  92.     @Override
  93.     public void hide() {
  94.     }
  95.  
  96.     @Override
  97.     public void pause() {
  98.     }
  99.  
  100.     @Override
  101.     public void resume() {
  102.     }
  103.  
  104.     @Override
  105.     public void dispose() {
  106.         batch.dispose();
  107.         skin.dispose();
  108.         atlas.dispose();
  109.         stage.dispose();
  110.        
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement