public static void createSkin() { /// Create a font BitmapFont font = new BitmapFont(); skin = new Skin(); skin.add("default", font); /// Create a texture Pixmap pixmap = new Pixmap( (int) Gdx.graphics.getWidth() / 4, (int) Gdx.graphics.getHeight() / 10, Pixmap.Format.RGB888); pixmap.setColor(Color.RED); pixmap.fill(); skin.add("background", new Texture(pixmap)); /// Create a button style TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); textButtonStyle.up = skin.newDrawable("background", Color.GRAY); textButtonStyle.down = skin.newDrawable("background", Color.DARK_GRAY); textButtonStyle.checked = skin.newDrawable("background", Color.DARK_GRAY); textButtonStyle.over = skin.newDrawable("background", Color.LIGHT_GRAY); textButtonStyle.font = skin.getFont("default"); skin.add("default", textButtonStyle); /// Create Title Style Label.LabelStyle labelStyle = new Label.LabelStyle(); labelStyle.fontColor = Color.RED; Pixmap titlePixmap = new Pixmap( (int) Gdx.graphics.getWidth() / 4, (int) Gdx.graphics.getHeight() / 10, Pixmap.Format.RGB888); titlePixmap.setColor(Color.CLEAR); titlePixmap.fill(); skin.add("titleBackground", new Texture(titlePixmap)); labelStyle.background = skin.newDrawable("titleBackground", Color.CLEAR); labelStyle.font = skin.getFont("default"); font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Nearest); skin.add("default", labelStyle); }
public MainMenuScreen(final SpaceLord2Game game, final ActionResolver resolver) { this.game = game; this.resolver = resolver; this.game.font = new BitmapFont(); this.game.font.getData().scale(3); this.game .font .getRegion() .getTexture() .setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); title = new Texture(Gdx.files.internal("space_lord_2_title.png")); backGround = new BackGround(); table = new Table(); table.defaults().width(600).padBottom(100); stage = new Stage(new FitViewport(GameConstants.GAME_WIDTH, GameConstants.GAME_HEIGHT)); Gdx.input.setInputProcessor(stage); launchSound = Gdx.audio.newSound(Gdx.files.internal("sounds/space.mp3")); buttonClick = Gdx.audio.newSound(Gdx.files.internal("sounds/button_click.mp3")); skin = new Skin(); skin.add("default", game.font); Pixmap pixmap = new Pixmap(100, 100, Pixmap.Format.RGBA8888); pixmap.setColor(Color.GRAY); pixmap.fill(); skin.add("white", new Texture(pixmap)); // Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this // doesn't overwrite the font. TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY); textButtonStyle.down = skin.newDrawable("white", Color.WHITE); textButtonStyle.checked = skin.newDrawable("white", Color.DARK_GRAY); textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY); textButtonStyle.font = skin.getFont("default"); skin.add("default", textButtonStyle); // Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a // name other than "default". final TextButton playButton = new TextButton("Play", textButtonStyle); table.add(playButton); table.row(); final TextButton leaderboardButton = new TextButton("Leaderboard", textButtonStyle); table.add(leaderboardButton); table.row(); final TextButton achievementButton = new TextButton("Achievements", textButtonStyle); table.add(achievementButton); table.row(); signInButton = new TextButton("Sign In", textButtonStyle); table.add(signInButton); table.row(); table.setPosition(GameConstants.GAME_WIDTH / 3, (GameConstants.GAME_HEIGHT / 5) * 2); stage.addActor(table); playButton.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { buttonClick.play(); game.setScreen(new SpaceLord2(game, resolver)); dispose(); } }); leaderboardButton.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { resolver.showLeaderboard(); } }); achievementButton.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { resolver.showAchievements(); } }); signInButton.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { buttonClick.play(); resolver.signIn(); } }); camera = new OrthographicCamera(); viewport = new FitViewport(GameConstants.GAME_WIDTH, GameConstants.GAME_HEIGHT, camera); viewport.apply(); camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0); }