Removing some parts of the canvas.
in
Programming Questions
•
2 years ago
Dear all interested readers,
I am currently making a game in Processing. I am done with the game itself, but I have problems with the visuals.
I want to draw a cross on my mouse that stretches over the entire canvas. It does that now, but when I move the mouse, the old cross is still standing at the old position. I cant use background(0);, because then I will lose all the images.
How can I rewrite the code so that everything stays on the screen, except the cross?
Thanks in advance!
Code:
int x,y;
float[][] oudeLocatie=new float[20000][2];
int count=0;
int menu=0;
PFont font;
int laatstex;
int laatstey;
void setup(){
font= loadFont("Serif-48.vlw");
textAlign(CENTER);
textFont(font,24);
frameRate(6);
size(screen.width,screen.height);
background(0);
}
void draw(){
if(menu==1){
ellipseMode(CENTER);
float x = random(0,screen.width);
float y = random(0,screen.height);
fill(255,0,0);
ellipse(x,y,10,10);
float waarde = 255;
waarde = dist(mouseX,mouseY,laatstex,laatstey);
fill(0,255,0);
ellipse(mouseX,mouseY,10,10);
for(int a=10;a<count+1;a++){
if(dist(mouseX,mouseY,laatstex,laatstey)>-1 && dist(mouseX,mouseY,laatstex,laatstey)<8 ){
fill(0,0,255);
ellipse(mouseX,mouseY,10,10);
}
for(int e=10;e<count+1;e++){
if(dist(mouseX,mouseY,laatstex,laatstey)>-1 && dist(mouseX,mouseY,laatstex,laatstey)<2 ){
menu=2;
}
for(int i=1;i<count+1;i++){
if(dist(mouseX,mouseY,oudeLocatie[i][0],oudeLocatie[i][1])>0 && dist(mouseX,mouseY,oudeLocatie[i][0],oudeLocatie[i][1])<10 ){
println(count);
menu=2;
}
}
}
}
oudeLocatie[count][0]=x;
oudeLocatie[count][1]=y;
count++;
}
if(menu==0){
background(255);
fill(0);
text("Run, you fools!",width/2,height/2);
}
if(menu==2){
fill(255);
text(count,width/2,100);
text("Game Over",width/2,height/2);
}
laatstex = mouseX;
laatstey = mouseY;
stroke(255);
line(mouseX,0,mouseX,screen.height);
line(0,mouseY,screen.width,mouseY);
}
void mousePressed(){
if(menu==0){
menu=1;
background(0);
}
if(menu==2){
menu=1;
count=0;
int[][] oudeLocatie=new int[1000][3];
background(0);
}
}
I am currently making a game in Processing. I am done with the game itself, but I have problems with the visuals.
I want to draw a cross on my mouse that stretches over the entire canvas. It does that now, but when I move the mouse, the old cross is still standing at the old position. I cant use background(0);, because then I will lose all the images.
How can I rewrite the code so that everything stays on the screen, except the cross?
Thanks in advance!
Code:
int x,y;
float[][] oudeLocatie=new float[20000][2];
int count=0;
int menu=0;
PFont font;
int laatstex;
int laatstey;
void setup(){
font= loadFont("Serif-48.vlw");
textAlign(CENTER);
textFont(font,24);
frameRate(6);
size(screen.width,screen.height);
background(0);
}
void draw(){
if(menu==1){
ellipseMode(CENTER);
float x = random(0,screen.width);
float y = random(0,screen.height);
fill(255,0,0);
ellipse(x,y,10,10);
float waarde = 255;
waarde = dist(mouseX,mouseY,laatstex,laatstey);
fill(0,255,0);
ellipse(mouseX,mouseY,10,10);
for(int a=10;a<count+1;a++){
if(dist(mouseX,mouseY,laatstex,laatstey)>-1 && dist(mouseX,mouseY,laatstex,laatstey)<8 ){
fill(0,0,255);
ellipse(mouseX,mouseY,10,10);
}
for(int e=10;e<count+1;e++){
if(dist(mouseX,mouseY,laatstex,laatstey)>-1 && dist(mouseX,mouseY,laatstex,laatstey)<2 ){
menu=2;
}
for(int i=1;i<count+1;i++){
if(dist(mouseX,mouseY,oudeLocatie[i][0],oudeLocatie[i][1])>0 && dist(mouseX,mouseY,oudeLocatie[i][0],oudeLocatie[i][1])<10 ){
println(count);
menu=2;
}
}
}
}
oudeLocatie[count][0]=x;
oudeLocatie[count][1]=y;
count++;
}
if(menu==0){
background(255);
fill(0);
text("Run, you fools!",width/2,height/2);
}
if(menu==2){
fill(255);
text(count,width/2,100);
text("Game Over",width/2,height/2);
}
laatstex = mouseX;
laatstey = mouseY;
stroke(255);
line(mouseX,0,mouseX,screen.height);
line(0,mouseY,screen.width,mouseY);
}
void mousePressed(){
if(menu==0){
menu=1;
background(0);
}
if(menu==2){
menu=1;
count=0;
int[][] oudeLocatie=new int[1000][3];
background(0);
}
}
1