# Keeping an ellipse after being drawn

**URL:** <https://discourse.processing.org/t/keeping-an-ellipse-after-being-drawn/20589>\
**Category:** Coding Questions\
**Created:** [May 7, 2020, 5:12pm UTC](https://discourse.processing.org/t/keeping-an-ellipse-after-being-drawn/20589 "2020-05-07T17:12:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CanGurbuz](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@CanGurbuz](https://discourse.processing.org/u/CanGurbuz)\
**Post date:** [May 7, 2020, 5:12pm UTC](https://discourse.processing.org/t/keeping-an-ellipse-after-being-drawn/20589/1 "2020-05-07T17:12:34Z")

</div>

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.

```auto
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

---

<div class="post-metadata">

**Author:** ![unique\_username](https://avatars.discourse-cdn.com/v4/letter/u/a88e57/32.png) [@unique\_username](https://discourse.processing.org/u/unique_username)\
**Post date:** [May 7, 2020, 6:54pm UTC](https://discourse.processing.org/t/keeping-an-ellipse-after-being-drawn/20589/2 "2020-05-07T18:54:38Z")

</div>

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.

```auto
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 🙂

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [May 7, 2020, 8:28pm UTC](https://discourse.processing.org/t/keeping-an-ellipse-after-being-drawn/20589/3 "2020-05-07T20:28:41Z")

</div>

```auto
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.

> [@CanGurbuz](#):
>
> 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.

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. 😄

---

<div class="post-metadata">

**Author:** ![unique\_username](https://avatars.discourse-cdn.com/v4/letter/u/a88e57/32.png) [@unique\_username](https://discourse.processing.org/u/unique_username)\
**Post date:** [May 8, 2020, 4:50pm UTC](https://discourse.processing.org/t/keeping-an-ellipse-after-being-drawn/20589/4 "2020-05-08T16:50:14Z")

</div>

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

```auto
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);
}

```
