Problems with screens in G4P library
in
Contributed Library Questions
•
7 months ago
Hi everyone,
I want to do a videogame or some kind of graphic interface, I have been worked with G4P library to create a nice interface but I have some problems. I need to change the screens when some button is press ( I want to have 6 screens) NOT at the same time, only when some button is press. I have this code but the screen doesn´t change, and the buttons doesn´t dissapear, does anyone have idea of who can I do?
Cheers
import g4p_controls.*;
GImageButton btnplay, btnStart, btnSettings, btnHelp, btnScores, btnSongs, btnClose;
GLabel lblOut;
GCustomSlider sdr1;
long timer;
String[] files;
String current_screen = "start_screen";
String last_screen = "start_screen";
PImage Partitura;
PImage director;
PImage directorarriba;
PImage directorenmedio;
PImage directorabajo;
PFont titulos;
PFont autor;
int i = 0;
void setup() { // this is run once.
size(640, 480); // canvas size (Variable aren't evaluated. Integers only, please.)
cursor(CROSS);
start_screen();
current_screen = "start_screen";
last_screen = "start_screen";
}
void draw() { // this is run repeatedly.
if((last_screen != "song_screen") && (current_screen == "song_screen")) {
//song_screen();
last_screen = "song_screen";
}
}
void start_screen(){
PImage fondo;
fondo = loadImage("fondo.jpg");
background(fondo);
cursor(CROSS);
files = new String[]{
"startOff.png", "startOn.png"
};
btnStart = new GImageButton(this, 250, 200, files);
files = new String[]{
"settingsOff.png", "settingsOn.png"
};
btnSettings = new GImageButton(this, 50, 100, files);
files = new String[]{
"helpOff.png", "helpOn.png"
};
btnHelp = new GImageButton(this, 1, 430, files);
files = new String[]{
"scoresOff.png", "scoresOn.png"
};
btnScores = new GImageButton(this, 50, 300, files);
files = new String[]{
"songsOff.png", "songsOn.png"
};
btnSongs = new GImageButton(this, 470, 300, files);
files = new String[]{
"closeOff.png", "closeOn.png"
};
btnClose = new GImageButton(this, 470, 100, files);
lblOut = new GLabel(this, 20, 5, 610, 20, "");
lblOut.setTextAlign(GAlign.CENTER, null);
timer = millis() -5000;
}
void song_screen(){
background(255);
files = new String[]{
"playon.png", "playoff.png"
};
btnplay = new GImageButton(this, 20, 20, files);
Partitura = loadImage("Partitura.png");
image(Partitura, 75, 50);
}
void settings_screen(){
background(200, 200, 255);
//cursor(CROSS);
sdr1 = new GCustomSlider(this, 20, 20, 260, 50, "blue18px");
sdr1.setShowDecor(false, true, true, true);
sdr1.setNbrTicks(5);
sdr1.setLimits(1, 1, 100);
}
void help_screen(){
background(200, 200, 255);
}
void scores_screen(){
background(200, 200, 255);
}
void songs_screen(){
background(200, 200, 255);
}
void close_screen(){
background(200, 200, 255);
}
void handleButtonEvents(GImageButton button, GEvent event){
if(button == btnStart){
lblOut.setText("Start");
println("play");
song_screen();
// I HAVE TO PUT THE NEXT CODE .SETVISIBLE TO QUIT THE BUTTONS
//btnStart.setVisible(false);
//btnSettings.setVisible(false);
//btnScores.setVisible(false);
//btnSongs.setVisible(false);
//btnClose.setVisible(false);
timer = millis();
}
if(button == btnSettings){
lblOut.setText("Settings");
println("settings");
settings_screen();
// I HAVE TO PUT THE NEXT CODE .SETVISIBLE TO QUIT THE BUTTONS
//btnStart.setVisible(false);
//btnSettings.setVisible(false);
//btnScores.setVisible(false);
//btnSongs.setVisible(false);
//btnClose.setVisible(false);
timer = millis();
}
if(button == btnHelp){
lblOut.setText("Help");
println("help");
help_screen();
// I HAVE TO PUT THE NEXT CODE .SETVISIBLE TO QUIT THE BUTTONS
//btnStart.setVisible(false);
//btnSettings.setVisible(false);
//btnHelp.setVisible(false);
//btnScores.setVisible(false);
//btnSongs.setVisible(false);
//btnClose.setVisible(false);
timer = millis();
}
if(button == btnScores){
lblOut.setText("Scores");
println("scores");
scores_screen();
// I HAVE TO PUT THE NEXT CODE .SETVISIBLE TO QUIT THE BUTTONS
//btnStart.setVisible(false);
//btnSettings.setVisible(false);
//btnHelp.setVisible(false);
//btnScores.setVisible(false);
//btnSongs.setVisible(false);
//btnClose.setVisible(false);
timer = millis();
}
if(button == btnSongs){
lblOut.setText("Songs");
println("songs");
songs_screen();
// I HAVE TO PUT THE NEXT CODE .SETVISIBLE TO QUIT THE BUTTONS
/*btnStart.setVisible(false);
btnSettings.setVisible(false);
btnHelp.setVisible(false);
btnScores.setVisible(false);
btnSongs.setVisible(false);
btnClose.setVisible(false);*/
timer = millis();
}
if(button == btnClose){
lblOut.setText("close");
println("close");
close_screen();
// I HAVE TO PUT THE NEXT CODE .SETVISIBLE TO QUIT THE BUTTONS
/*btnStart.setVisible(false);
btnSettings.setVisible(false);
btnHelp.setVisible(false);
btnScores.setVisible(false);
btnSongs.setVisible(false);
btnClose.setVisible(false);*/
timer = millis();
}
}
public void handleSliderEvents(GSlider slider){
print("integer value:" + slider.getValueI() + "float value:" + slider.getValueF());
}
1