Shared splitscreen camera

Version:

1.0

Added on:

09 Jul 2014 09:45

Tags:

Description:
When playing two-player splitscreen, the screen is shared between both players instead of being literally split in two whenever the two of you are near enough for this to be possible.
  1. bool cameraShared = false;
  2. void onMain() {
  3.   if (jjLocalPlayerCount == 2) {
  4.     jjPLAYER@ player1 = jjLocalPlayers[0];
  5.     jjPLAYER@ player2 = jjLocalPlayers[1];
  6.     float dx = player1.xPos - player2.xPos;
  7.     float dy = player1.yPos - player2.yPos;
  8.     if (abs(dx) < jjResolutionWidth && abs(dy) < jjResolutionHeight) { //might want to tweak the distance requirement to make it a little tighter
  9.       cameraShared = true;
  10.       //nothing to be done about the black line in the middle of the screen...
  11.       if (jjGameTicks & 7 == 0) { //a slight delay, causing the scrolling to be more gradual
  12.         int lx = int(player1.xPos + player2.xPos - jjResolutionWidth) / 2;
  13.         int ty = int(player1.yPos + player2.yPos - jjResolutionHeight) / 2;
  14.         if (lx < 0) lx = 0; //should also add a check for the far right side of the level
  15.         if (ty < 0) ty = 0; //likewise the bottom
  16.         player1.cameraFreeze(lx + player1.subscreenX, ty + player1.subscreenY, false, false);
  17.         player2.cameraFreeze(lx + player2.subscreenX, ty + player2.subscreenY, false, false);
  18.       }
  19.     } else if (cameraShared) {
  20.       cameraShared = false;
  21.       player1.cameraUnfreeze();
  22.       player2.cameraUnfreeze();
  23.     }
  24.   }
  25. }