Keeping an ellipse after being drawn

Hey everyone.

I am trying to make a cursor for the map of the game I want to make. I want this cursor of the map like it is in APEX LEGENDS i.e there is a line from the top of the screen to the bottom for your MouseX position and same for mouseY. Here is the code I have written so far.

void setup(){
size(600,600);
background(100,10,0);
}

void draw(){
  background(100,10,0);
  if (mousePressed && (mouseButton == LEFT)) {
    ellipse(mouseX, mouseY, 10, 10);
    fill(255,0,0);
  }
 
  line(0, mouseY, width, mouseY);
  line(mouseX, 0, mouseX, height); 
}

I want the ellipse when mouse button is pressed to stay, and not get overdrawn by background(). I appreciate any help you throw my way.
P.S just got in to programming

Thanks

1 Like

I suggest using a boolean variable to test whether the player is on the map or not- if so, activate the cursor when they’re on, versus when they hold the mouse. Void draw() tests one every frame whether or not the mouse is being clicked, so you’d have to hold it down. I’ve included a short example code for you to look at, and please format your code using the </> button, which makes your code easier to read.

boolean onMapScreen;
//Whether or not the player is viewing the map.

void setup(){
size(600,600);
background(100,10,0);
}

void draw(){
background(100,10,0);
onMapScreen=true;                  //Confirms the player is looking at the map.
if (onMapScreen) {                 //If the player is looking at the map, 
ellipse(mouseX, mouseY, 10, 10);   //active the cursor.
fill(255,0,0);
}

line(0, mouseY, width, mouseY);
line(mouseX, 0, mouseX, height);
}

Edit; if someone else responds with a different solution you should probably use theirs, I’ve been out of practice for a while :slightly_smiling_face:

1 Like
void draw() {
  background(100, 10, 0);
  onMapScreen=true;                  //Confirms the player is looking at the map.
  if (onMapScreen) {                 //If the player is looking at the map, 
    ellipse(mouseX, mouseY, 10, 10); //active the cursor.
    fill(255, 0, 0);
  }
  line(0, mouseY, width, mouseY);
  line(mouseX, 0, mouseX, height);
}

@unique_username unfortunately this doesn’t do the job because the if statement will always be true since you set the variable true immediately before.

I don’t understand your code appears to do that - the ellipse shows when the mouse button is pressed and disappears when released. More explanation needed. :smile:

1 Like

Well, he would alter the code so that the variable was only true when the player requested to see the map.

boolean onMapScreen;
//Whether or not the player is viewing the map.

void setup(){
size(600,600);
background(100,10,0);
}

void draw(){
background(100,10,0);
onMapScreen=true;                  //Confirms the player is looking at the map.
//You would have an if() statement so that onMapScreen was true when the player
//requested to see the map
if (onMapScreen) {                 //If the player is looking at the map, 
ellipse(mouseX, mouseY, 10, 10);   //active the cursor.
fill(255,0,0);
}

line(0, mouseY, width, mouseY);
line(mouseX, 0, mouseX, height);
}