Hi everyone, i want to make a camera who follow my player ( i allready make a topic about it but now it’s a bit different)
so, i need a camera who follow the player but not linked to the screen so if i change the size of my screen it does not cause issue.
here’s a basic example:
Player player;
LimitOfTheWorld limitoftheworld;
int worldSize = 500;
void setup(){
frame.setResizable(true);
size(250,250);
PVector pos = new PVector(250,250);
PVector pos2 = new PVector(10,10);
player = new Player(pos);
limitoftheworld = new LimitOfTheWorld(pos2);
}
void draw(){
background(255);
fill(0,0,0);
rect(worldSize,worldSize,0,0);
player.display();
player.playerMvt();
limitoftheworld.display();
}
class LimitOfTheWorld{
PVector position;
float r;
LimitOfTheWorld(PVector pos2){
position = pos2.get();
r = 450;
}
void display(){
noFill();
rect(position.x,position.y,r,r);
stroke(5);
}
}
class Player{
PVector position;
float r;
Player(PVector pos){
position = pos.get();
r = 10;
}
void display(){
fill(255,0,0);
ellipse(position.x,position.y,r,r);
}
void playerMvt(){
if(keyPressed){
if(key == CODED){
if(keyCode == UP){
position.y -= 10;
}
if(keyCode == DOWN){
position.y += 10;
}
if(keyCode == LEFT){
position.x -= 10;
}
if(keyCode == RIGHT){
position.x += 10;
}
}
}
}
}
So how can i make a “camera” who follow my player ?
Thanks for your help and your time.