Hey guys. I’m new to LibGDX and fairly new to Java. I do however have experience in other languages such as C#. I’ve read through a basic java book and am now moving on to libgdx…It seems a lot of the tutorials are outdated…I’m working on a basic brick breaker game and using this tutorial: http://code.google.com/p/libgdx/wiki/SimpleApp
I’m just using the camera and spritebatch code and such from it…but it doesn’t seem to be working correctly. I’m getting an exception on the batch.draw method. When I run it, the application shows briefly, and it looks like the paddle is stretched across the screen, but then it shuts down with the exception. I’ve been searching around to no avail. I appreciate any help. I’ll post my code below as it isn’t much.
{EDIT} Actually, it doesn’t throw an exception with the code below…but the paddle disappears and it’s just a white screen.
package com.psillicoder.brickbreaker;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
//import com.badlogic.gdx.graphics.Texture.TextureFilter;
//import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
//import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
public class Game implements ApplicationListener {
private OrthographicCamera camera;
private SpriteBatch batch;
//private Texture ballImage;
private Texture paddleImage;
//rectangles
//Rectangle ballRect;
Rectangle paddleRect;
@Override
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
paddleImage = new Texture(Gdx.files.internal("data/paddle.PNG"));
//ballImage = new Texture(Gdx.files.internal("data/ball.png"));
camera = new OrthographicCamera(1, h/w);
batch = new SpriteBatch();
//paddle
paddleRect = new Rectangle();
paddleRect.x = 400/2 - 64/2;
paddleRect.y = 20;
paddleRect.width = 64;
paddleRect.height = 16;
}
@Override
public void dispose() {
batch.dispose();
//ballImage.dispose();
paddleImage.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(paddleImage, paddleRect.x, paddleRect.y);
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}