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.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; // Screen som kommer upp p applikationen nr spelaren // har frlorat samtliga etraliv. public class FailedScreen implements Screen, InputProcessor { // Hmtar tillgnglig storlek p spelskrm att visa. float x = Gdx.graphics.getWidth(); float y = Gdx.graphics.getHeight(); private int width, height; // SKapar aktuell spritebatch samt enskilda texturer. private SpriteBatch spriteBatch; private Texture failedScreenTexture; private Game KEAGame; // Konstruktor fr att skapa en screen, kopplas till aktuellt spel genom // ingende variabel. public FailedScreen(Game ga) { KEAGame = ga; } @Override public void render(float delta) { // Renderar aktuella texturer. spriteBatch.begin(); spriteBatch.draw(failedScreenTexture, 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; } // Hmtar aktuella sprites. @Override public void show() { spriteBatch = new SpriteBatch(); failedScreenTexture = new Texture(Gdx.files.internal("images/gameover.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 } // Nr skrmen avslutas slngs sprites ivg. @Override public void dispose() { spriteBatch.dispose(); failedScreenTexture.dispose(); } @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 / 6) && x1 < (width / 2 - width / 6) + width / 3 && y1 > (y - ((height / 4) + height / 8)) && y1 < (y - (height / 4))) { KEAGame.setScreen(new MainMenuScreen(KEAGame)); } return true; } @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; } }