Added GameScreen

This commit is contained in:
Mike Schwörer 2014-08-10 00:24:45 +02:00
parent 9fe821bf53
commit 76cc7e8e47
3 changed files with 115 additions and 19 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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
}
}