From 76cc7e8e476c1dd759f1d9b7f84423089a6fdfa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 10 Aug 2014 00:24:45 +0200 Subject: [PATCH] Added GameScreen --- core/src/de/samdev/colorrunner/CRGame.java | 30 ++++----- .../samdev/colorrunner/actors/DemoActor.java | 42 +++++++++++++ .../colorrunner/screens/GameScreen.java | 62 +++++++++++++++++++ 3 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 core/src/de/samdev/colorrunner/actors/DemoActor.java create mode 100644 core/src/de/samdev/colorrunner/screens/GameScreen.java diff --git a/core/src/de/samdev/colorrunner/CRGame.java b/core/src/de/samdev/colorrunner/CRGame.java index e02f956..165c432 100644 --- a/core/src/de/samdev/colorrunner/CRGame.java +++ b/core/src/de/samdev/colorrunner/CRGame.java @@ -1,27 +1,19 @@ package de.samdev.colorrunner; -import com.badlogic.gdx.ApplicationAdapter; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.Game; -public class CRGame extends ApplicationAdapter { - SpriteBatch batch; - Texture img; +import de.samdev.colorrunner.screens.GameScreen; + +public class CRGame extends Game { - @Override - public void create () { - batch = new SpriteBatch(); - img = new Texture("badlogic.jpg"); - } + private GameScreen gameScreen; @Override - public void render () { - Gdx.gl.glClearColor(1, 0, 0, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - batch.begin(); - batch.draw(img, 0, 0); - batch.end(); + public void create() { + gameScreen = new GameScreen(); + + //---------------------------------- + + setScreen(gameScreen); } } diff --git a/core/src/de/samdev/colorrunner/actors/DemoActor.java b/core/src/de/samdev/colorrunner/actors/DemoActor.java new file mode 100644 index 0000000..915a412 --- /dev/null +++ b/core/src/de/samdev/colorrunner/actors/DemoActor.java @@ -0,0 +1,42 @@ +package de.samdev.colorrunner.actors; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.InputListener; + +public class DemoActor extends Actor { + Texture texture = new Texture(Gdx.files.internal("data/jet.png")); + public boolean started = false; + + public DemoActor() { + setBounds(getX(), getY(), texture.getWidth(), texture.getHeight()); + + addListener(new InputListener() { + @Override + public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { + System.out.println("touch my one more time"); + return true; + } + }); + } + + @Override + public void draw(Batch batch, float alpha) { + batch.draw(texture, this.getX(), this.getY(), + this.getOriginX(), this.getOriginY(), + this.getWidth(), this.getHeight(), + this.getScaleX(), this.getScaleY(), + this.getRotation(), + 0, 0, + texture.getWidth(), texture.getHeight(), + false, false); + } + + @Override + public void act(float delta) { + super.act(delta); + } +} diff --git a/core/src/de/samdev/colorrunner/screens/GameScreen.java b/core/src/de/samdev/colorrunner/screens/GameScreen.java new file mode 100644 index 0000000..78095a7 --- /dev/null +++ b/core/src/de/samdev/colorrunner/screens/GameScreen.java @@ -0,0 +1,62 @@ +package de.samdev.colorrunner.screens; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.utils.viewport.ExtendViewport; + +public class GameScreen implements Screen { + + private Stage stage; + + public GameScreen() { + stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(),Gdx.graphics.getHeight())); //TODO fix w/h ??? + + } + + @Override + public void render(float delta) { + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + stage.act(delta); + stage.draw(); + } + + @Override + public void resize(int width, int height) { + // TODO Auto-generated method stub + + } + + @Override + public void show() { + Gdx.input.setInputProcessor(stage); + + } + + @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 + + } + +}