Relatively positioned textured background

Version:

1.0

Added on:

06 May 2016 18:36

Tags:

Description:
Adjusts the fade position of a Tunnel or Warp Horizon textured background to reflect each player's distance from the center of the level. For example, a player in the top left corner will see the background fading away to the bottom right and a player in the dead center will see the background fading away right behind them. Options are provided to clamp the range/s of fade positions. Works with splitscreen.
//you may customize these four values
const float FadePosXMin = 0.0;
const float FadePosXMax = 1.0;
const float FadePosYMin = 0.0;
const float FadePosYMax = 1.0;





const int LevelWidth = jjLayers[4].width * 32;
const int LevelHeight = jjLayers[4].height * 32;
const float LevelWidthF = float(LevelWidth);
const float LevelHeightF = float(LevelHeight);
const float FadePosXRange = FadePosXMax - FadePosXMin;
const float FadePosYRange = FadePosYMax - FadePosYMin;
void onDrawLayer4(jjPLAYER@ play, jjCANVAS@) {
  const jjPLAYER@ nextPlayer = jjLocalPlayers[(play.localPlayerID + 1) % jjLocalPlayerCount];
  if (LevelWidth != jjSubscreenWidth)
    jjTexturedBGFadePositionX = (1.0 - float(nextPlayer.cameraX) / (LevelWidthF - jjSubscreenWidth)) * FadePosXRange + FadePosXMin;
  else
    jjTexturedBGFadePositionX = 0.5; //don't divide by zero!
  if (LevelHeight != jjSubscreenHeight)
    jjTexturedBGFadePositionY = (1.0 - float(nextPlayer.cameraY) / (LevelHeightF - jjSubscreenHeight)) * FadePosYRange + FadePosYMin;
  else
    jjTexturedBGFadePositionY = 0.5; //don't divide by zero!
}