Hi all.
I am looking to create pages in my sketch in which the buttons I want to use are assigned different orders. For example, on the intro page, button A takes you to page 2. On page 2 button A changes the background colour. Is this possible? I have attempted to create a class for the new page but it doesn’t want to accept the new button code. I should also note that I have configured an Xbox controller to use the buttons.
Here is an example:
Main sketch page:
String gamestate;
nextPage page2;
intro introPage;
import net.java.games.input.*;
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;
ControlIO control;
ControlDevice gpad;
float px, py;
void setup() {
size(1080, 1920);
gamestate = "INTRO";
page2 = new nextPage();
introPage = new intro();
// Initialise the ControlIO
control = ControlIO.getInstance(this);
// Find a device that matches the configuration file
gpad = control.getMatchedDevice("test");
if (gpad == null) {
println("No suitable device configured");
System.exit(-1); // End the program NOW!
}
}
void draw() {
if (gamestate == "INTRO") {
introPage.setup();
introPage.draw();
} else if (gamestate == "PAGE2") {
page2.setup();
page2.draw();
}
}
void getUserInput() {
px = map(gpad.getSlider("X Axis").getValue(), -1, 1, 0, width);
py = map(gpad.getSlider("Y Axis").getValue(), -1, 1, 0, height);
}
Class 1 (intro_page):
class intro {
void setup() {
gamestate = "INTRO";
gpad.getButton("Abtn").plug(this, "gotopage2", ControlIO.ON_RELEASE);
}
void draw() {
background(0);
fill(255);
rect (50, 50, 50, 50);
}
void gotopage2() {
getUserInput();
gamestate = "PAGE2";
}
}
Class 2 (Page2):
class nextPage {
void setup() {
gamestate = "PAGE2";
gpad.getButton("Abtn").plug(this, "changeBg", ControlIO.ON_RELEASE);
}
void draw() {
background(255);
fill(0);
rect (50, 50, 50, 50);
}
void changeBg() {
getUserInput();
background(100, 0, 100);
}
}
The error code I am getting on intro_page
Configuration
test
Abtn Abtn 1 BUTTON Button 0 0 0.0 0.0