I have made a game in Slick2D that works just fine in Windows OS. The same can not be said for Linux. The graphics flicker a lot!
This is a major problem to all Linux and probably Mac users.
I am not using any LWJGL calls, so what can be causing this?
Some code:
Starting the game:
Engine engine = new Engine(title, stage, replay, frame);
AppGameContainer agc = new AppGameContainer(engine, stage.visibleWidth, stage.visibleHeight, false);
engine.setAppGameContainer(agc);
agc.setTargetFrameRate(60);
agc.setShowFPS(false);
agc.setVSync(true);
agc.start();
Rendering method:
@Override
public void render(GameContainer gc, Graphics g) throws SlickException
{
g.setAntiAlias(AA);
if(state == GameState.PAUSED)
{
renderPause(g);
return;
}
if(prevPaused && stage.music != null)
stage.music.setVolume(Stage.MUSIC_VOLUME);
prevPaused = false;
if(autoTranslate)
{
float focusX = focus.currX + focus.width /2,
focusY = focus.currY + focus.height / 2;
tx = Math.min(stage.width - stage.visibleWidth, Math.max(0, focusX - stage.visibleWidth / 2));
ty = Math.min(stage.height - stage.visibleHeight, Math.max(0, focusY - stage.visibleHeight / 2));
}
if(vertSpeed > 0)
moveVert();
if(horSpeed > 0)
moveHor();
if(scaleSpeed > 0)
scale();
g.translate(-tx, -ty);
g.scale(sx, sy);
g.rotate(rx, ry, ang);
if(stage.map != null)
g.drawImage(stage.map, 0,0);
if(stage.background != null)
stage.background.getObject().draw(0,0);
for(ReplayData rd : ghosts)
{
DataImage di = rd.character.getFrame();
if(rd.character.visible && di != null)
di.draw(rd.character.currX + rd.character.offsetX, rd.character.currY + rd.character.offsetY);
}
if(!mainHighPriority)
{
DataImage mainImg = main.getFrame();
if(main.visible && mainImg != null)
mainImg.draw(main.currX + main.offsetX, main.currY + main.offsetY);
}
if (state == GameState.DEAD && main.death != null)
{
Image img = main.death.getObject();
img.draw(main.currX + main.offsetX, main.currY + main.offsetY);
}
for (Enemy enemy : stage.enemies)
if (enemy.visible)
{
if(enemy.particleBehind)
for(ParticleSystem ps : enemy.particles)
ps.render(enemy.currX + enemy.partOffsetX, enemy.currY + enemy.partOffsetY);
if(enemy.drawSpecialBehind)
enemy.drawSpecial(g);
drawObject(enemy);
if(!enemy.drawSpecialBehind)
enemy.drawSpecial(g);
if(!enemy.particleBehind)
for(ParticleSystem ps : enemy.particles)
ps.render(enemy.currX + enemy.partOffsetX, enemy.currY + enemy.partOffsetY);
}
for(GameObject go : stage.stageObjects)
drawObject(go);
stage.playEffectEvents(g);
if(mainHighPriority)
{
DataImage mainImg = main.getFrame();
if(main.visible && mainImg != null)
mainImg.draw(main.currX + main.offsetX, main.currY + main.offsetY);
}
if(stage.foreground != null)
stage.foreground.getObject().draw(0,0);
g.translate(tx, ty);
g.rotate(rx, ry, -ang);
renderStatusBar(g);
if(state == GameState.DEAD)
renderDeadText(g);
}
DataImage extends slick Image and only add pixel data for fast pixel-perfect collision.
So why is the game flickering on Linux?