Hey again;
First i want to say hi to reBirth,haha.
Anyway,im loving this forum. anyway, college and work eats my time but im trying to learn java stuff nonetheless, anyway, i just wanted some judgment on this code, how can i improve it?
package mainLoop;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.FPSLogger;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import models.Background;
import models.Plane;
/**
*
* @author André
*/
public class ShooterGame implements ApplicationListener {
// constant useful for logging
public static final String LOG = ShooterGame.class.getSimpleName();
// a libgdx helper class that logs the current FPS each second
private FPSLogger fpsLogger;
private Plane plane;
private Background background;
public ShooterGame() {
plane = new Plane();
background = new Background();
}
@Override
public void create() {
fpsLogger = new FPSLogger();
//Start bg draw
Texture backgroundTexture = background.getBackgroundTexture();
drawBackground(backgroundTexture,512,512);
//End bg draw
Texture planeTexture = plane.getPlaneTexture();
draw(planeTexture,plane.getxPos(),plane.getyPos());
}
@Override
public void render() {
fpsLogger.log();
update();
//the following code clears the screen with the given RGB color (green)
Gdx.gl.glClearColor( 0f, 1f, 0f, 1f );
Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT );
//Start bg draw
Texture backgroundTexture = background.getBackgroundTexture();
drawBackground(backgroundTexture,512,512);
//End bg draw
Texture planeTexture = plane.getPlaneTexture();
draw(planeTexture,plane.getxPos(),plane.getyPos());
}
public void update()
{
plane.setxPos(plane.getxPos() + 1);
plane.setyPos(plane.getyPos() + 1);
}
public void drawBackground(Texture texture,int width,int height)
{
//Start bg draw
Texture backgroundTexture = background.getBackgroundTexture();
SpriteBatch bgBatch = new SpriteBatch();
bgBatch.begin();
bgBatch.draw(backgroundTexture,0,0,width,height);
bgBatch.end();
//End bg draw
}
public void draw(Texture texture,int xPos,int yPos)
{
Sprite sprite = new Sprite(texture);
sprite.setX(xPos);
sprite.setY(yPos);
//
SpriteBatch spriteBatch = new SpriteBatch();
spriteBatch.begin();
//
sprite.draw(spriteBatch);
spriteBatch.flush();
spriteBatch.dispose();
//
spriteBatch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}