Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to properly handle with textBox's in draw() function ?

$
0
0

Hi all!

In my project i've managed to create a sketch with two states representing a main screen, and once you click a button it changes to second state (at this point, everything is fine). The problem comes when (in the second state) I try to write a username in textBox that i made using Control5P. The text appear and disappear instantaneously and i know this happens because the function that make the textBox is inside the Draw(). But i couldn't make it work properly. How should i handle this?

Thanks in advance

Part of the code i've got so far.

void draw() {
  switch (state){
    case main_screen:
      show_main_screen();
      break;
    case login_screen:
      show_login();
      break;
  }


}

void  show_main_screen(){
//some code
}

void show_login(){

//some code

String[] Login = {"Username","Password"};
    PFont font = createFont("arial",20);

    textBox= new ControlP5(this);

    int y=20;
    int x = 20;
    int spacing=90;
    for(String s : Login){
      textBox.addTextfield(s)
         .setValue(username)
         .setPosition(x,y)
         .setSize(160,50)
         .setFont(font)
         .setFocus(true)
         .setColor(color(255,0,0))
         .setAutoClear(false);
         ;

        y+=spacing;
    }

   textFont(font);

Viewing all articles
Browse latest Browse all 2896

Trending Articles