# How can I continue or separate mousePressed?

**URL:** https://discourse.processing.org/t/how-can-i-continue-or-separate-mousepressed/30509
**Category:** Coding Questions
**Tags:** homework
**Created:** [June 5, 2021, 12:28pm UTC](https://discourse.processing.org/t/how-can-i-continue-or-separate-mousepressed/30509 "2021-06-05T12:28:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tzmy](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tzmy](https://discourse.processing.org/u/tzmy)
#### Post date: [June 5, 2021, 12:28pm UTC](https://discourse.processing.org/t/how-can-i-continue-or-separate-mousepressed/30509/1 "2021-06-05T12:28:49Z")

</div>

I want to make a very simple screen-changing game with processing.  
I am a beginner in coding and processing, so I use mousePressed for screen changing.  
But I found that I can’t do some functions.

1. How can I continue mousePressed work? I thought a screen is put ‘on’ the earlier one, but it seems that it just divides the part of the same screen. I want the work of mousePressed to be continued after I release the mouse.

2. How can I separate functions after mousePressed? I want to get a new background and moving image with mousePressed, but when I put it under mousePressed, the motion just proceeds when the mouse is pressed. I want mousePressed to change screens, but not to control motion. I want the motion to proceed regardless of the mouse.

Thank you!

code

```auto
float x[]=new float[8];
float y[]=new float[8];
float won=100;
float xspeed[]=new float[8];
float yspeed[]=new float[8];

PImage wall; PImage file;
PImage sky; PImage boat;

void setup(){
  size(800,800);
 
wall=loadImage("wall.jpg"); image(wall,0,0); wall.resize(800,800);
file=loadImage("file.png"); image(file,0,0); file.resize(250,250);
  
sky=loadImage("sky.jpg"); image(sky,0,0); sky.resize(800,800);
boat=loadImage("boat.png"); image(boat,0,0); boat.resize(40,40);

image(wall,0,0); image(file,275,265);

 for(int i=0; i<3; i++){
   x[i]=i*won;
    xspeed[i]=random(1,8);
    yspeed[i]=random(1,8);
    
 } }

void draw(){
if(mousePressed == true && mouseX>=220 && mouseX<=245 && mouseY>=650 && mouseY<=675) {
image(sky,0,0);

   for(int i=0; i<3; i++){
    y[i]=y[i]+yspeed[i];

  image(boat,200,y[i]+won/2);

   if(y[i]>height){
   y[i]=-200;
  } }
}}

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 5, 2021, 12:54pm UTC](https://discourse.processing.org/t/how-can-i-continue-or-separate-mousepressed/30509/2 "2021-06-05T12:54:11Z")

</div>

Hello,

Welcome `:)`

Please format your code as a courtesy to the community:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

`:)`

---

<div class="post-metadata">

### Author: ![tzmy](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tzmy](https://discourse.processing.org/u/tzmy)
#### Post date: [June 5, 2021, 1:16pm UTC](https://discourse.processing.org/t/how-can-i-continue-or-separate-mousepressed/30509/3 "2021-06-05T13:16:00Z")

</div>

I’m sorry. I didn’t know I have to format the code. I edited it. Thank you 🙂

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 5, 2021, 1:30pm UTC](https://discourse.processing.org/t/how-can-i-continue-or-separate-mousepressed/30509/4 "2021-06-05T13:30:30Z")

</div>

Hello,

There are lots of resources (tutorials, references, examples, etc.) here:  
_[processing.org](http://processing.org/)_

Check out the examples that come with Processing.  
These are in the menu under _File \> Examples…\>_ :

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/79e77e5fe2fd04ba44fc1cfeddb89e95740741e7.png)

Check out the refrences:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/12836abc10ec03ba16f18d204ac684ef93f4dd5d.png)

Other resources:

- Coding Train on YouTube [Coding Train](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)
- [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)

I encourage you to peruse the resource’s available to you on the Processing website and the examples in the Processing app.

`:)`
