Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mygdx.makescents;
- import com.badlogic.gdx.Game;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.utils.ScreenUtils;
- public class MakesCentsGame extends Game {
- private SpriteBatch batch;
- private Texture img;
- private BitmapFont font;
- private GameScreen gameScreen;
- private GameTitle gameTitle;
- @Override
- public void create() {
- gameTitle = new GameTitle("Makes Cents", 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- gameScreen = new GameScreen(this); // pass the game instance to the GameScreen constructor
- // Create a new SpriteBatch and load the image
- batch = new SpriteBatch();
- img = new Texture("pennyfriends.jpg");
- // Create a new BitmapFont with white color
- font = new BitmapFont();
- font.setColor(Color.WHITE);
- // Set the font's properties
- font.getData().setScale(2f); // Set the font scale
- font.getData().setLineHeight(50f); // Set the line height
- System.out.println("Game created");
- }
- @Override
- public void render() {
- // Clear the screen
- ScreenUtils.clear(0, 0, 0, 1); // Set the background color to black
- // Get the screen width and height
- float screenWidth = Gdx.graphics.getWidth();
- float screenHeight = Gdx.graphics.getHeight();
- // Get the image width and height
- float imageWidth = img.getWidth();
- float imageHeight = img.getHeight();
- // Calculate the position to center the image
- float x = (screenWidth - imageWidth) / 2;
- float y = (screenHeight - imageHeight) / 2;
- // Begin the SpriteBatch and draw the image
- batch.begin();
- batch.draw(img, x, y);
- // Draw the text with the white font
- font.draw(batch, "Welcome to Makes Cents!", 100, 200);
- // End the SpriteBatch
- batch.end();
- if (Gdx.input.justTouched()) {
- System.out.println("Screen changed to GameScreen");
- setScreen(gameScreen); // Call setScreen() with gameScreen instance
- }
- }
- @Override
- public void dispose() {
- // Dispose of the SpriteBatch, image, and font
- if (batch != null) {
- batch.dispose();
- }
- if (img != null) {
- img.dispose();
- }
- if (font != null) {
- font.dispose();
- }
- System.out.println("Game disposed");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement