Hi guys.
Im trying to make a little plane move on screen and learn about this lib and hmm, i got the same problem that i had in java2D and i wanted to know what should i do :
Each time it passes render it moves the sprite BUT, it gets dragged and it doesnt erase the texture that was before unless this code is there :
:point:
http://imageshack.us/a/img209/1107/withoutclearcode.jpg
http://imageshack.us/a/img822/2448/withclearcode.jpg
: :
:
:
package mainLoop;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
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.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;
public ShooterGame() {
plane = new Plane();
}
@Override
public void create() {
fpsLogger = new FPSLogger();
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 );
Texture planeTexture = plane.getPlaneTexture();
draw(planeTexture,plane.getxPos(),plane.getyPos());
}
public void update()
{
plane.setxPos(plane.getxPos() + 2);
plane.setyPos(plane.getyPos() + 2);
}
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() {
}
}
package imagesSounds;
import com.badlogic.gdx.graphics.Texture;
/**
*
* @author André
*/
public class TexturesLoader
{
/**Chamado Apenas pelas Models*/
public static Texture getPlaneTexture()
{
Texture splashTexture = new Texture( "D:\\Arquivos && Java\\MeusProjetosJava\\ImagesVideosAudio\\Images\\plane.jpg" );
return splashTexture;
}
}