-1

I want to addsplitscreen to my game and so I tried to use Camera2D, but now only one character (the blue one (it should be the left one)) is showed with the top left corner in the middle of the screen. Also I used ToggleFullScreen, because without this, it would be showed in the top left corner of the screen. Here my code

(main)

Player player1{ -1, RED};
Player player2{ 1, BLUE };
...
BeginMode2D(player1.playerCamera);
player1.tick( GetFrameTime() );
EndMode2D();

BeginMode2D(player2.playerCamera);
player2.tick( GetFrameTime() );
EndMode2D();

( player)

#include "raylib.h"
#include "player.h"
#include "Fullscreen.h"

Player::Player(int placeOfTheCharacter, Color color) {
    playerColor = color;
    place = placeOfTheCharacter;

    ToggleFullscreen();
    screenWidth = GetMonitorWidth(GetCurrentMonitor());
    screenHeight = GetMonitorHeight(GetCurrentMonitor());

    Vector2 playerPosition = CenterPositionOnScreen(playerWidth, playerHeight, place);
    playerRec = { playerPosition.x, playerPosition.y, static_cast<float>(playerWidth), static_cast<float>(playerHeight) };
            
    playerCamera.offset = { screenWidth/2.f, screenHeight/2.f };
    playerCamera.rotation = 0.f;
    playerCamera.target = playerPosition;
    playerCamera.zoom = 1.f;
}

void Player::tick( float dT) {
    // controls
    DrawRectangleRec(playerRec, playerColor);
}

(Fullscreen)

#include "raylib.h"
#include "Fullscreen.h"

// ... and defined in a .cpp file
float screenWidth = GetMonitorWidth(GetCurrentMonitor());
float screenHeight = GetMonitorHeight(GetCurrentMonitor());

// Function to center the Position based on the screensize (the middle of the half of the screen)
Vector2 CenterPositionOnScreen(int objectWidth, int objectHeight, int place) {
    Vector2 center;
    center.x = (GetScreenWidth() - objectWidth) / 2 - (GetScreenWidth() / 4) * place;
    center.y = (GetScreenHeight() - objectHeight) / 2;
    return center;
}

When I remove the camera it works properly.

  • I've solved it, the offset was the problem because I only made one for the two. Also I've writen 0,0 instead of the Middle of the half of the screen. Code Change: `playerCamera.offset = CenterPositionOnScreen(playerWidth, playerHeight, place);` – Andi Friend Aug 07 '23 at 11:19
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 08 '23 at 04:14

0 Answers0