I have draw and update functions like this:
Camera2D guiCam = new Camera2D();
updateWorld(){
guiCam.position.x+=7f;
}
public class Background extends DynamicGameObject {
int dirX=-1;
public Background(float x, float y, float width, float height,float velX) {
super(x, y, width, height);
velocity.x = velX;
}
public void update(float deltaTime,float cameraX) {
position.x = cameraX * 0.3f; // magic number to make the background move slowly
if(position.x + bounds.width-1200 <= 0)
position.x+= 2400;
}
}
void render()
{
batcher.beginBatch(Assets.background);
batcher.drawSprite(world.onKatman.position.x, 240, 2400, 480, Assets.backgroundRegion);
if(world.onKatman.position.x + world.onKatman.bounds.width-1200 < 800)
batcher.drawSprite(world.onKatman.position.x + world.onKatman.bounds.width, 240, 2400, 480, Assets.backgroundRegion);
batcher.endBatch();
}So this draws a parallax effect with two background objects but it draws it statically. I'm creating a 2D side-scrolling game and I'm translating my character and my camera position along x axis. So I have to translate my parallax effect with my camera but when I add to background `position.x` it doesn't work. How can I solve this?
Edited by Mehmet Turan, 17 May 2012 - 05:11 AM.






