Advertisement
TeamOneButton

GameScreen.java

Mar 22nd, 2023 (edited)
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.mygdx.makescents;
  2.  
  3. import com.badlogic.gdx.Game;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.graphics.Color;
  6. import com.badlogic.gdx.graphics.Texture;
  7. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  8. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  9. import com.badlogic.gdx.utils.ScreenUtils;
  10.  
  11. public class GameScreen extends com.badlogic.gdx.ScreenAdapter {
  12.     private Game game;
  13.     private SpriteBatch batch;
  14.     private BitmapFont font;
  15.     private Texture backgroundTexture;
  16.  
  17.     public GameScreen(Game game) {
  18.         this.game = game;
  19.     }
  20.  
  21.     @Override
  22.     public void show() {
  23.         batch = new SpriteBatch();
  24.  
  25.         // Create a new BitmapFont with black color
  26.         font = new BitmapFont();
  27.         font.setColor(Color.BLACK);
  28.  
  29.         // Set the font's properties
  30.         font.getData().setScale(2f); // Set the font scale
  31.         font.getData().setLineHeight(50f); // Set the line height
  32.        
  33.         // Load the background texture
  34.         backgroundTexture = new Texture("atypicalGamescreen.png");
  35.     }
  36.  
  37.     @Override
  38.     public void render(float delta) {
  39.         // Clear the screen to black
  40.         ScreenUtils.clear(Color.BLACK);
  41.  
  42.         // Begin the SpriteBatch and draw the background texture
  43.         batch.begin();
  44.         batch.draw(backgroundTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  45.  
  46.         // Draw the text with the black font
  47.         font.draw(batch, "This is the game screen", 100, 200);
  48.         batch.end();
  49.  
  50.         if (Gdx.input.justTouched()) {
  51.             System.out.println("Touched screen - advancing to GameOverScreen");
  52.             game.setScreen(new GameOverScreen(game)); // Set the screen to the GameOverScreen
  53.         }
  54.     }
  55.  
  56.     @Override
  57.     public void dispose() {
  58.         if (batch != null) {
  59.             batch.dispose();
  60.         }
  61.         if (font != null) {
  62.             font.dispose();
  63.         }
  64.         if (backgroundTexture != null) {
  65.             backgroundTexture.dispose();
  66.         }
  67.     }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement