EDIT: The actual code I used to accomplish this with the AndEngine:
import org.andengine.engine.camera.Camera;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
public class ParallaxSprite extends Sprite {
private float parallaxSpeed;
private float offsetX = 0;
private float offsetY = 0;
/**
* Creates an instance of {@link ParallaxSprite}
* @param pX
* @param pY
* @param parallaxSpeed
* @param pTextureRegion
* @param pVertexBufferObjectManager
*/
public ParallaxSprite(float pX, float pY, float parallaxSpeed, ITextureRegion pTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
this.parallaxSpeed = parallaxSpeed;
this.offsetX = pX - (pX * parallaxSpeed);
this.offsetY = pY - (pY * parallaxSpeed);
}
@Override
protected void onManagedDraw(GLState pGLState, Camera pCamera) {
pGLState.pushModelViewGLMatrix();
{
final float x = this.offsetX + this.parallaxSpeed * pCamera.getXMin();
final float y = this.offsetY + this.parallaxSpeed * pCamera.getYMin();
pGLState.translateModelViewGLMatrixf(x, y, 0);
/* Draw only self. */
this.preDraw(pGLState, pCamera);
this.draw(pGLState, pCamera);
this.postDraw(pGLState, pCamera);
}
pGLState.popModelViewGLMatrix();
}
}