Hi everyone i tried to make an ecosystem and for now its working great, mostly because i receive a lot of help from here. ( see topic : A pathfinding solution).
But now my world gonna be too small for my ecosystem, so i need to make a world bigger than my game window and a camera following the player.
For now i cant find a way to make it or a decent tutorial. Can someone guide or help me ?
yes thats a very basic 2d top down game.
Thanks for your advice, how do i make my world bigger than my game window ?
what i mean by that is, my game screen size is 1200,900 for now and its the limit of my world. So how do i make a bigger world(sorry i cant find a better word for that) than my game screen
For example you have your “world” bigger than your canvas (1000*1000) and you translate to px,py (the coordinates of the up left corner) to draw your world (here it’s a rect).
Then you can move your world by using the arrows keys :
int w = 1000, h = w;
int px,py;
void setup() {
size(500, 500);
px = width/2 - w/2;
py = height/2 - h/2;
}
void draw() {
background(0);
pushMatrix();
translate(px,py);
fill(255);
rect(px,py,w,h);
popMatrix();
}
void keyPressed(){
if (keyCode == LEFT){
px -= 5;
}else if (keyCode == UP){
py -= 5;
}else if (keyCode == RIGHT){
px += 5;
}else if (keyCode == DOWN){
py += 5;
}
}
hi i have a problem (one more), i use eclipse with java and i use processing as library.
I dont know how to “translate” your code.
so here is my code
my main class:
public class Game extends PApplet{
public static void main(String[] args){
PApplet.main("Game");
}
public void settings(){
size(1200,900);
}
World world;
public void setup(){
world = new World(this);
}
public void draw(){
background(255);
world.run();
}
}
my world class : (i dont put any of my code its not relevant i think)
public class World {
PApplet parent;
public World(PApplet p){
parent = p;
}
public void run(){
}
}
i think maybe i need a player class but i wait for your advices before create it.
I’m don’t know too much about “Java classes syntax” but I think that you can add px and py propreties to your class World so when you draw your world in your canvas, translate to px and py.
Then you can update them (when you press a key for example) :
well what you propose help me, now my world is bigger than my screen. Thanks
Now i need a way to center the “camera” (center of my screen) on my player but i have a lot of bugs and i dont know why. ex here : my player appear on the top left of my white area and dont move but the “camera” move properly.
here is my code for now:
(game class dont change except i remove the background)