Java tutorial
// Copyright 2012 Anton Holm, Arez Arazu, Gustav Larsson // // 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 net.dat.killemall.screens; import net.dat.killemall.KillEmAll; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.ClickListener; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle; import com.badlogic.gdx.scenes.scene2d.ui.tablelayout.Table; public class MainMenuScreen implements Screen, InputProcessor { private Game KEAGame; private Stage stage; private SpriteBatch spriteBatch; private Texture backgroundTexture; // Hmtar tillgnglig storlek fr skrmen. float x = Gdx.graphics.getWidth(); float y = Gdx.graphics.getHeight(); private int width, height; public MainMenuScreen(Game ga) { // Kopplar aktuell screen till applikationen. KEAGame = ga; } // Metod fr att rendera aktuell Screen. @Override public void render(float delta) { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1); spriteBatch.begin(); // Mlar ut bakgrundsbild. spriteBatch.draw(backgroundTexture, 0, 0, x, y); spriteBatch.end(); // Mlar ut scen och aktrer. } // Om telefonen vrids t ngot hll eller om upplsningen // p annat vis frndras s ndras ven maximalt tilltna // storlek p innehll p skrmen. Hr frndras tabellens // storlek fr att ritas inne i skrmen korrekt. @Override public void resize(int width, int height) { this.width = width; this.height = height; } //Nr denna screen startas hmtas aktuell spritebatch upp @Override public void show() { spriteBatch = new SpriteBatch(); backgroundTexture = new Texture(Gdx.files.internal("images/startgame.png")); Gdx.input.setInputProcessor(this); } @Override public void hide() { // TODO Auto-generated method stub } @Override public void pause() { // TODO Auto-generated method stub } @Override public void resume() { // TODO Auto-generated method stub } @Override public void dispose() { // TODO Auto-generated method stub } @Override public boolean touchDown(int x1, int y1, int pointer, int button) { // If-satserna avgr var p skrmen som spelaren trycker genom att rama in vissa pixlar i //x-led och y-led, nr spelaren rr skrmen inom dessa byts skrmen till //spelskrmen respektive instruktionerna. if (x1 > (width / 2 - width / 10) && x1 < (width / 2 - width / 10) + width / 4 && y1 > (y - (height / 2 - height / 20 + height / 8)) && y1 < (y - (height / 2 - height / 20))) { KEAGame.setScreen(new GameScreen(KEAGame)); } if (x1 > (width / 2 - width / 8) && x1 < ((width / 2 - width / 8) + width / 3) && y1 > (y - (height / 4 + height / 8)) && y1 < (y - height / 4)) { System.out.println("instruction pushed!"); KEAGame.setScreen(new InstructionScreen(KEAGame)); } return true; } @Override public boolean keyDown(int keycode) { // TODO Auto-generated method stub return false; } @Override public boolean keyUp(int keycode) { // TODO Auto-generated method stub return false; } @Override public boolean keyTyped(char character) { // TODO Auto-generated method stub return false; } @Override public boolean touchUp(int x, int y, int pointer, int button) { // TODO Auto-generated method stub return false; } @Override public boolean touchDragged(int x, int y, int pointer) { // TODO Auto-generated method stub return false; } @Override public boolean touchMoved(int x, int y) { // TODO Auto-generated method stub return false; } @Override public boolean scrolled(int amount) { // TODO Auto-generated method stub return false; } }