How can I continue or separate mousePressed?

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

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;
  } }
}}

Hello,

Welcome :)

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

:)

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

1 Like

Hello,

There are lots of resources (tutorials, references, examples, etc.) here:
processing.org

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

Check out the refrences:

Other resources:

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

:)