2D moving objects chasing by camera?
in
Programming Questions
•
1 year ago
Hello, I just want to ask how can i chase an object with camera while moving in 2D. I want to make a game like mario but i don't know how can i chase mario.
I wrote this but it didn't work because i dont know that what will I write instead of centerx, centery,centerz and upx, upy, upz. I made a lot of research but i couldn't find.( I wrote PVector for only see where is my rect).Do we need to use translate ?
I just want to chase this rect with camera in 2D area just you know.. like mario
boolean r;
boolean u;
boolean d;
boolean l;
float x=0;
float y=400;
PVector kare;
void setup()
{
size(800,600,P3D);
kare=new PVector(x,y);
}
void draw()
{
background(255);
fill(0);
noStroke();
smooth();
camera(kare.x, kare.y,0 ,width/2, height/2, 0.0,
0.0, 0.0, 0.0);
translate(50, 50, 0);
rect(kare.x,kare.y,30,30);
if (r)
{
kare.x=kare.x+5;
}
if (u)
{
kare.y=kare.y-5;
}
if (d)
{
kare.y=kare.y+5;
}
if (l)
{
kare.x=kare.x-5;
}
println(kare);
}
void keyPressed()
{
if(keyCode==RIGHT || key =='d')
{
r=true;
}
if(keyCode==UP || key == 'w')
{
u=true;
}
if(keyCode==DOWN || key == 's')
{
d=true;
} if(keyCode==LEFT || key == 'a')
{
l=true;
}
}
void keyReleased()
{
if(keyCode==RIGHT || key == 'd')
{
r=false;
}
if(keyCode==UP || key == 'w')
{
u=false;
}
if(keyCode==LEFT || key == 'a')
{
l=false;
}
if(keyCode==DOWN || key == 's')
{
d=false;
}
}
1