I want to create a typing menu, where the player types their name after clicking (yes, after clicking, because the click directs to this menu)... But I also don't want the name to stay forever (like it would if I used void draw)! I just want the typing on this particular menu.
The code is actually very sketchy, it's my first time using processing
/** intro */
// nekogame (under construction)
// by: SG
// nyan~( u w u )n welcomyan~!
/** setting images */
// the cat sprites can be found at kiko-the-eevee.deviantart.com/art/Neko-China-Sprites-458076035
// the background picture can be found at www.deviantart.com/art/Grassland-Battleback-for-RPG-Maker-XP-513228900
PImage cenario;
PImage cenario2;
PImage cenario3;
PImage gift;
PImage start;
PImage down;
PImage up;
PImage right;
PImage left;
PImage fight1;
PImage fight2;
PImage fight3;
PImage fight4;
PImage name;
/** setting text */
// this info can be found at processing.org:8443/tutorials/typography/
String letters = "";
PFont square;
/** setting sound */
// this info can be found at poanchen.github.io/blog/2016/11/15/how-to-add-background-music-in-processing-3.0
// the song can be found at www.youtube.com/watch?v=0FCzpTit_aU
import processing.sound.*;
SoundFile file;
String audioName = "sound.mp3";
String path;
/** setup */
void setup(){
size(640, 480);
square = loadFont("SquareFont-48.vlw");
textFont(square);
fill(0);
textSize(20);
path = sketchPath(audioName);
file = new SoundFile(this, path);
file.play();
start = loadImage ("start.png");
cenario = loadImage("bg1.png");
cenario2 = loadImage ("bg2.png");
cenario3 = loadImage ("bg3.png");
gift = loadImage ("goodend.png");
background(start);
down = loadImage("cat1.png");
up = loadImage("7.png");
right = loadImage("cat5.png");
left = loadImage("cat3.png");
fight1 = loadImage("bad1.png");
fight2 = loadImage("bad2.png");
fight3 = loadImage("bad3.png");
fight4 = loadImage("bad4.png");
name = loadImage("name.png");
}
/** draw */
void draw() {
if (pmouseX < mouseX){
cursor(right);
}
if (pmouseX > mouseX){
cursor(left);
}
if (pmouseY < mouseY){
cursor(down);
}
if (pmouseY > mouseY){
cursor(up);
}
if (mouseX >= 620){
background(cenario2);
}
if (mouseY >= 460){
background(cenario3);
}
}
/** mouse */
void mousePressed(){
if (mousePressed){
background(name);
float cursorPosition = textWidth(letters);
} else{
text(letters,0, 245);
}
}
/** keys */
void keyPressed(){
if (key == BACKSPACE){
if (letters.length() > 0){
letters = letters.substring(0, letters.length()-1);
}
} else if (textWidth(letters+key) < width){
letters = letters + key;
}
if (key == CODED){
if (keyCode == UP){
background(gift);
}
}
if (key == CODED){
if (keyCode == RIGHT){
background(fight2);
}
}
if (key == CODED){
if (keyCode == DOWN){
background(fight3);
}
}
if (key == CODED){
if (keyCode == LEFT){
background(fight4);
}
}
if (key == ENTER){
background(cenario);
}
if (key == TAB){
background(fight1);
file.stop();
noCursor();
}
if (key == DELETE){
background(start);
file.play();
}
}