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 com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.Screen; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; 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 InstructionScreen implements Screen, InputProcessor { private Game KEAGame; private Stage stage; private SpriteBatch spriteBatch; private Texture backgroundTexture; // Hmtar tillgnglig storlek fr aktuell screen att visas p. float x = Gdx.graphics.getWidth(); float y = Gdx.graphics.getHeight(); private int width, height; public InstructionScreen(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); // Mlar ut bakgrundsbild spriteBatch.begin(); spriteBatch.draw(backgroundTexture, 0, 0, x, y); spriteBatch.end(); } // 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; } // Vid ppnande av denna screen hmtas fljande instanser upp // vid skapande @Override public void show() { spriteBatch = new SpriteBatch(); backgroundTexture = new Texture(Gdx.files.internal("images/instructions.png")); // Fr att kunna hantera att spelaren rr p skrmen och koppla detta // Till handlingar stts en inputprocessor p denna Screen 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 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 touchDown(int x1, int y1, int pointer, int button) { // If-satsen 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 //Main Menu if (x1 > (width / 2 - width / 7) && x1 < (width / 2 - width / 7) + width / 3 && y1 > (y - (height / 7 + height / 8)) && y1 < (y - (height / 7))) { KEAGame.setScreen(new MainMenuScreen(KEAGame)); } return true; } //Fljande metoder ingr nr man hmtar en inputprocessor i bibliotek, det //r dock inget som behver anvndas i applikationen. @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; } }