master
GammelJAN 5 years ago
parent 0734d173a9
commit 79a3530a49

@ -2,32 +2,73 @@ package com.trs.main;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
public class Main extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
public class Main extends ApplicationAdapter implements InputProcessor{
Stage stage;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
stage = new Stage(new ScreenViewport());
Player p = new Player();
stage.addActor(p);
stage.setKeyboardFocus(p);
Gdx.input.setInputProcessor(stage);
}
@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();
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
@Override
public void dispose () {
batch.dispose();
img.dispose();
}
@Override
public boolean keyDown(int i) {
return false;
}
@Override
public boolean keyUp(int i) {
return false;
}
@Override
public boolean keyTyped(char c) {
return false;
}
@Override
public boolean touchDown(int i, int i1, int i2, int i3) {
return false;
}
@Override
public boolean touchUp(int i, int i1, int i2, int i3) {
return false;
}
@Override
public boolean touchDragged(int i, int i1, int i2) {
return false;
}
@Override
public boolean mouseMoved(int i, int i1) {
return false;
}
@Override
public boolean scrolled(float f, float f1) {
return false;
}
}

@ -0,0 +1,67 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.trs.main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
/**
*
*
* @author Jan
*/
public class Player extends Actor{
Texture t;
Player(){
t = new Texture(Gdx.files.internal("badlogic.jpg"));
setBounds(50, 50, t.getWidth(), t.getHeight());
}
@Override
protected void positionChanged() {
setX(getX());
setY(getY());
super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void act(float delta) {
if(Gdx.input.isKeyPressed(Input.Keys.D)){
setX(getX()+10);
}
if(Gdx.input.isKeyPressed(Input.Keys.A)){
setX(getX()-10);
}
if(Gdx.input.isKeyPressed(Input.Keys.W)){
setY(getY()+10);
}
if(Gdx.input.isKeyPressed(Input.Keys.S)){
setY(getY()-10);
}
super.act(delta); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(t, getX(), getY());
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean remove() {
return super.remove(); //To change body of generated methods, choose Tools | Templates.
}
}
Loading…
Cancel
Save