Game Development Reference
In-Depth Information
xRel += dimension.x;
// mountain right
reg = regMountainRight;
batch.draw(reg.getTexture(),
origin.x + xRel + position.x * parallaxSpeedX,
origin.y + yRel + position.y,
origin.x, origin.y,
dimension.x, dimension.y,
scale.x, scale.y,
rotation,
reg.getRegionX(), reg.getRegionY(),
reg.getRegionWidth(), reg.getRegionHeight(),
false, false);
xRel += dimension.x;
}
// reset color to white
batch.setColor(1, 1, 1, 1);
}
@Override
public void render (SpriteBatch batch) {
// 80% distant mountains (dark gray)
drawMountain(batch, 0.5f, 0.5f, 0.5f, 0.8f);
// 50% distant mountains (gray)
drawMountain(batch, 0.25f, 0.25f, 0.7f, 0.5f);
// 30% distant mountains (light gray)
drawMountain(batch, 0.0f, 0.0f, 0.9f, 0.3f);
}
We have added a fifth parameter to drawMountain() that ranges between 0.0 and
1.0 and describes the distance and its scrolling speed. The scrolling depends on the
camera's current position, which is then multiplied with the distance factor. This is
the reason why we have also added a new method called updateScrollPosition() ,
which needs to be called in every update cycle where the camera can move.
Make the following changes to the WorldController class:
public void update (float deltaTime) {
handleDebugInput(deltaTime);
if (isGameOver()) {
timeLeftGameOverDelay -= deltaTime;
if (timeLeftGameOverDelay< 0) backToMenu();
} else {
handleInputGame(deltaTime);
}
level.update(deltaTime);
 
Search WWH ::




Custom Search