Advertisement
Guest User

Simple GImage Button

a guest
Apr 7th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. //libraries demo
  2.  
  3. //import necessary libraries
  4. import g4p_controls.*;
  5.  
  6. //declare necessary variables
  7. PImage photo;
  8. GImageButton myButton;
  9. String [] files;
  10. float startTime;
  11. boolean startScreen;
  12. color bgColor;
  13.  
  14.  
  15. void setup () {
  16.   size (2560, 1600);
  17.   //boolean to keep track of which screen draws
  18.   startScreen = true;
  19.   photo = loadImage("firewatch.jpg");
  20.   //string array to store file names of button states
  21.   files = new String [] {"Up.png", "Hover.png", "Down.png",};
  22.   //instantiate new button (note that it takes files, the string array, as an argument)
  23.   myButton = new GImageButton (this, width/2-600, height/2-600, files);
  24. }
  25. void draw () {
  26.   if(startScreen) {
  27.   background (photo);
  28.   } else {
  29.     background (0, 100, 200);
  30.     fill ((millis()-startTime)/10*255/width, 50, 50);
  31.     rect ((millis()-startTime)/10, height/2,100,100);
  32.   }
  33. }
  34. //necessary function when using G4P
  35. void handleButtonEvents (GImageButton button, GEvent event) {
  36.   if (button==myButton){
  37.     //all code that covers what we want to happen when button is pressed
  38.     println ("Button Pressed");
  39.     myButton.dispose();
  40.     myButton=null;
  41.     startScreen=false;
  42.     startTime = millis();
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement