Relatively positioned textured background

Version:

1.0

Added on:

06 May 2016 20: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.
  1. //you may customize these four values
  2. const float FadePosXMin = 0.0;
  3. const float FadePosXMax = 1.0;
  4. const float FadePosYMin = 0.0;
  5. const float FadePosYMax = 1.0;
  6.  
  7.  
  8.  
  9.  
  10.  
  11. const int LevelWidth = jjLayers[4].width * 32;
  12. const int LevelHeight = jjLayers[4].height * 32;
  13. const float LevelWidthF = float(LevelWidth);
  14. const float LevelHeightF = float(LevelHeight);
  15. const float FadePosXRange = FadePosXMax - FadePosXMin;
  16. const float FadePosYRange = FadePosYMax - FadePosYMin;
  17. void onDrawLayer4(jjPLAYER@ play, jjCANVAS@) {
  18.   const jjPLAYER@ nextPlayer = jjLocalPlayers[(play.localPlayerID + 1) % jjLocalPlayerCount];
  19.   if (LevelWidth != jjSubscreenWidth)
  20.     jjTexturedBGFadePositionX = (1.0 - float(nextPlayer.cameraX) / (LevelWidthF - jjSubscreenWidth)) * FadePosXRange + FadePosXMin;
  21.   else
  22.     jjTexturedBGFadePositionX = 0.5; //don't divide by zero!
  23.   if (LevelHeight != jjSubscreenHeight)
  24.     jjTexturedBGFadePositionY = (1.0 - float(nextPlayer.cameraY) / (LevelHeightF - jjSubscreenHeight)) * FadePosYRange + FadePosYMin;
  25.   else
  26.     jjTexturedBGFadePositionY = 0.5; //don't divide by zero!
  27. }