Shared splitscreen camera

Version:

1.0

Added on:

09 Jul 2014 07: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.
bool cameraShared = false;
void onMain() {
  if (jjLocalPlayerCount == 2) {
    jjPLAYER@ player1 = jjLocalPlayers[0];
    jjPLAYER@ player2 = jjLocalPlayers[1];
    float dx = player1.xPos - player2.xPos;
    float dy = player1.yPos - player2.yPos;
    if (abs(dx) < jjResolutionWidth && abs(dy) < jjResolutionHeight) { //might want to tweak the distance requirement to make it a little tighter
      cameraShared = true;
      //nothing to be done about the black line in the middle of the screen...
      if (jjGameTicks & 7 == 0) { //a slight delay, causing the scrolling to be more gradual
        int lx = int(player1.xPos + player2.xPos - jjResolutionWidth) / 2;
        int ty = int(player1.yPos + player2.yPos - jjResolutionHeight) / 2;
        if (lx < 0) lx = 0; //should also add a check for the far right side of the level
        if (ty < 0) ty = 0; //likewise the bottom
        player1.cameraFreeze(lx + player1.subscreenX, ty + player1.subscreenY, false, false);
        player2.cameraFreeze(lx + player2.subscreenX, ty + player2.subscreenY, false, false);
      }
    } else if (cameraShared) {
      cameraShared = false;
      player1.cameraUnfreeze();
      player2.cameraUnfreeze();
    }
  }
}