Very very easy code!!
Hi
I know I know it is very easy and not a big deal but sometimes I feel my brain is locked!
In the following simple code I want to do something that, until the mouse does not press again on the other rect , the text display.
Red rect shows an image with word “Hi”. ( “Hi stays put until the mouse pressed on the blue rect”)
Blue rect shows an image with word “Bye”.(“Bye stays put until the mouse pressed on the blue rect”)
Please name the images in the data folder as (“00” and “01”)
- int numFrames=2;
- PImage[] images=new PImage[numFrames];
- PFont font;
- String A = "Hi";
- String B = "Bye";
- int k;
- void setup()
- {
- size(500,500);
- background(187);
- font = loadFont("Serif.bolditalic-20.vlw");
- }
- void draw()
- {
- println(mouseX+" "+mouseY);
- fill(255,0,0);
- rect(10,400,50,50);
- fill(0,0,255);
- rect(100,400,50,50);
- for(k=0; k<images.length; k++)
- {
- String imageName=nf(k,2)+".jpg";
- images[k]=loadImage(imageName);
- }
- textFont(font);
- if(mousePressed==false)
- {
- noStroke();
- fill(187);
- rect(0,230,100,100);
- }
- function(10,60,0,A);
- function(100,150,1,B);
- }
- /*void mouseReleased()
- {
- fill(187);
- rect(0,230,100,100);
- }*/
- void function(int minx, int maxx, int pic,String letter) //@@@
- {
- if((mousePressed==true)&&(mouseX>=minx)&&(mouseX<=maxx)&&
- (mouseY>=400)&&(mouseY<=450))
- {
- image(images[pic], 10,10,100,100);
- fill(0);
- text(letter,50,250);
- }
- }