I’m making a 2D survival game, with a top-down perspective. I don’t want the world to be infinite, so i made the map a square, with the sides being 200.000 pixels long. The script for moving the player works fine (so the player can’t move in the x or y axis beyond (-)100.000), but for some weird reason, the visual border is WAY off, even though the map square is placed 100.000 pixels from the map center, and has 200.000 pixels in side length.
here is the code. the framerate is set to 6000 for testing purposes, the player moves 100 times faster than normal, which is useful for getting to the border quickly. it is at 60 normally. there is also a mini map which i didn’t include here. (i disabled some code that’s associated with rocks that get placed on the map, these work fine)
int camx = 0;
int camy = 0;
void setup() {
surface.setTitle("ScrollingTest");
frameRate(6000);
size(1920, 1080);
background(0);
//spawnRock(50);
}
void draw() {
background(0);
fill(#329032);
strokeWeight(10);
stroke(#CB212C);
rect(-100000-camx, -100000-camy, 200000, 200000); //THIS is the line that draws the map square!
//executeRock();
drawPlayer();
inputPlayer();
drawUI();
}
void drawPlayer() {
fill(50);
strokeWeight(1);
stroke(0);
rect(width/2, height/2, 100, 100);
}
void inputPlayer() {
if (keyPressed == true) {
if (key == 'w') {
if (camy > -100000) {
camy = camy-10;
}
}
}
if (keyPressed == true) {
if (key == 'a') {
if (camx > -100000) {
camx = camx-10;
}
}
}
if (keyPressed == true) {
if (key == 's') {
if (camy < 100000) {
camy = camy+10;
}
}
}
if (keyPressed == true) {
if (key == 'd') {
if (camx < 100000) {
camx = camx+10;
}
}
}
}
void drawUI() {
drawMap();
fill(255);
textSize(20);
text("X: " + camx + " Y: " + (0-camy), 50, 800);
}