Java tutorial
/* * Copyright 2013 Baris Sencan (baris.sencan@me.com) * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package com.amerticum.chosenchess.view; import com.amerticum.chosenchess.Assets; import com.amerticum.chosenchess.ChoSenGame; import com.amerticum.chosenchess.Constants; import com.amerticum.chosenchess.model.Echiquier; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL30; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.ScreenViewport; import java.util.regex.Pattern; /** * A {@link SplashScreen} * * @author Baris Sencan */ public class MainMenu implements Screen { private Stage stage; private BitmapFont font; private TextButton netPlayButton, computerPlayButton; private Echiquier echiquier; public MainMenu(Echiquier echiquier) { this.echiquier = echiquier; initUI(); } private void initUI() { stage = new Stage(new ScreenViewport()); Gdx.input.setInputProcessor(stage); netPlayButton = new TextButton(" Play with a friend ", Assets.skin, "menu"); computerPlayButton = new TextButton(" Play computer ", Assets.skin, "menu"); netPlayButton.setPosition(Gdx.graphics.getWidth() / 2 - netPlayButton.getWidth() / 2, Gdx.graphics.getHeight() - netPlayButton.getHeight() - Constants.MARGE); computerPlayButton.setPosition(Gdx.graphics.getWidth() / 2 - netPlayButton.getWidth() / 2, netPlayButton.getY() - netPlayButton.getHeight() - Constants.MARGE); computerPlayButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { ChoSenGame.game.setScreen(new GameScreen(echiquier)); } }); netPlayButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { } }); stage.addActor(netPlayButton); stage.addActor(computerPlayButton); } @Override public void render(float delta) { Gdx.gl.glClearColor(192 / 255f, 192 / 255f, 192 / 255f, 1); Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); stage.draw(); } @Override public void resize(int width, int height) { stage.getViewport().update(width, height); Gdx.graphics.requestRendering(); } @Override public void show() { } @Override public void dispose() { stage.dispose(); } @Override public void hide() { } @Override public void pause() { } @Override public void resume() { } }