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

Text field input is displayed but not editable

$
0
0

Hi guys, I'm a newbie in processing I am working on a game that requires text field, but unfortunately it is not editable, and I do not know why,

here's the code:

`import controlP5.*;

//What level of the game the player is at //import controlP5.*; //controlP5 cp5; int level =0; //What is being shown, 1=Instructions, 2=Dead screen, 3=Win screen, 4=In game int screen = 1; //Time limit for levels (if 0, timelimit doesn't apply) int timelimit = 0; //Stage of instructions the player is it int instructionsStage=1; int r = int(random(2, 30)); int value = int(random(1, 10)); int parse=0; String toCheck=""; //did you die in the example of the instructions?(0 = dead, 1 = alive) int demoDead=1;

//MAIN GAMEPLAY array for mouse positions, for black slug effect, and position of robot (xpos[0],ypos[0]) int[] xpos=new int[40]; int[] ypos=new int[40];

//TUTORIAL PT1 array for mouse positions, for black slug effect, and position of robot (xpos[0],ypos[0]) int[] xpos1=new int[40]; int[] ypos1=new int[40];

String tx = "DONE! CLICK TO MOVE ON"; PFont f; boolean mouseIsDown = false; boolean loading = false;

import controlP5.*; ControlP5 cp5; String url1, url2;

//Function for the slug and robot (1 for normal game play, 2 for non-robot levels, 3 for tutorial pt1) /* void slug(int a){ if(a==1 || a==2){ background(255); //array values of mouse positions shift for (int i=0; i<xpos.length-1; i++){ xpos[i]=xpos[i+1]; ypos[i]=ypos[i+1]; } //current mouse position is allways joining the array xpos[xpos.length-1]=mouseX; ypos[ypos.length-1]=mouseY; //creates slug effect for (int i=0; i<xpos.length; i++){ noStroke(); fill(255-i6); ellipse(xpos[i],ypos[i],(i/4)3,(i/4)*3); } } if(a==3){ demoDead=1; //array values of mouse positions shift for (int i=0; i<xpos1.length-1; i++){ xpos1[i]=xpos1[i+1]; ypos1[i]=ypos1[i+1]; } //last array position is moved along x (controls speed and direction the example slug moves in the tutorial) if((xpos1[xpos1.length-1])<=200){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+10); } if(((xpos1[xpos1.length-1])>=200)&&((xpos1[xpos1.length-1])<=225)){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+1); } if(((xpos1[xpos1.length-1])>=225)&&((xpos1[xpos1.length-1])<=400)){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+10); } if(((xpos1[xpos1.length-1])>=400)&&((xpos1[xpos1.length-1])<435)){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+1); } if((xpos1[0])>=435){ xpos1[xpos1.length-1]=((xpos1[xpos1.length-1])+1); } //hides slug and robot for short period before restaring the demo if((xpos1[0])>405){ text("Dead",350,232); demoDead=0; } //restarts the demo if((xpos1[0])>=440){ demoDead=1; //resetting array for(int i=0;i<xpos1.length;i++){ xpos1[i]=80; ypos1[i]=300; } }

//RESTART THE DEMO ONCE FINISHED //creates slug effect //only if it's ment to be visible if (demoDead==1){ for (int i=0; i<xpos1.length; i++){ noStroke(); fill(255-i6); ellipse(xpos1[i],ypos1[i],(i/4)3,(i/4)*3); } }
} if (a==1){
for (int i=0; i<xpos.length; i++){ //draws robot being on last mouse position in the array fill(255,0,0); ellipse(xpos[0],ypos[0],50,50); } } if (a==3){
for (int i=0; i<xpos.length; i++){ //draws robot being on last position in the array //only if it's ment to be visible if (demoDead==1){ fill(255,0,0); ellipse(xpos1[0],ypos1[0],50,50); } } } }

*/

//Reused button, 1=instrutions part 1, 2=instructions part 2, 3=begin game, 4=continue game

void button(int a) { fill(255, 234, 41); noStroke(); if (a==1) { rect(300, 500, 150, 50); fill(0); textAlign(CENTER); textSize(32); text("Start", 375, 535); } if (a==2) { rect(300, 500, 150, 50); fill(0); text("Next", 375, 535); } if (a==3) { rect(300, 100, 150, 50); fill(0); text("Start!", 350, 132); } if (a==4) {

rect(300, 100, 150, 50);
fill(0);
text("Resume", 350, 132);

} }

//INSTRUCTIONS function (a=level of the game, 0=not started) void instructions() { background(255, 255, 255); textSize(72); cursor(CROSS); fill(0); if (instructionsStage==1) { textAlign(CENTER); text("Wa7ed Men Khamsa!", 100, 100, 600, 600); button(1); if ((mousePressed)&&((mouseX>300)&&(mouseX<450)&&(mouseY>500)&&(mouseY<550))) { instructionsStage++; } } if (instructionsStage==2) {

{
  background(255);
  if (mouseIsDown == true)
  {
    loading = true;
    frameCount = 1;
  }
  if (loading == false)
  {

    /* int r = int(random(2,30));
     text (r, 400, 300);

     fill(0);
     textAlign(CENTER);
     textSize(20);
     text (tx, 400, 400);

     if(mouseIsDown == true){ */
    instructionsStage++;
  }
}
if (loading == true)
{
  fill(0);
  textAlign(CENTER);
  textSize(32);
  text ("Counting the Passengers: " + int((frameCount%301) / 3) + "%", 400, 250);
  rect(300, 300, 204, 24);
  fill(255);
  int fillX = ((frameCount%301) / 3 * 2);
  rect(502, 302, fillX-200, 20);
  if (frameCount%301 == 0)
  {
    loading = false;
  }
}

}

/* text("The scientits have programmed each robot to follow your moves exactly when you hold down your mouse button, but 1 second behind, so if you move too slowly, it will catch you up, which will get you killed.",100,425,600,600); button(2); //slug(3); / / if((mousePressed)&&((mouseX>300)&&(mouseX<450)&&(mouseY>100)&&(mouseY<150))){ instructionsStage++; } } */ if (instructionsStage==3) {

text (r, 400, 300);


textSize(32);
text("Passengers", 100, 350, 600, 600);
button(2);
if ((mousePressed)&&((mouseX>300)&&(mouseX<450)&&(mouseY>500)&&(mouseY<550))) {
  instructionsStage++;
}

} if (instructionsStage==4) { textSize(20); text(r, 130, 100); text("*", 160, 100); text(value, 190, 100); text("=", 220, 100); text(toCheck, 250, 100); //converting string to int parse = parseInt(toCheck);

  cp5 = new ControlP5(this);

cp5.addTextfield("textInput_1").setPosition(20, 100).setSize(200, 40).setAutoClear(false); //cp5.addTextfield("textInput_2").setPosition(20, 170).setSize(200, 40).setAutoClear(false); cp5.addBang("Submit").setPosition(240, 170).setSize(80, 40);

text("If the ticket price is 1 L.E, and each passenger pays 5 L.E, what is the total of their payment?", 100, 400, 600, 600);




if (level==0) {
  button(3);
} else {
  button(4);
}
if ((mousePressed)&&((mouseX>300)&&(mouseX<450)&&(mouseY>100)&&(mouseY<150))) {
  screen=4;
  instructionsStage=0;
}

} }

void setup() { size(800, 660); background(255); //MAIN GAMEPLAY initializing array of mouse positions as all equalling 0 for (int i=0; i<xpos.length; i++) { xpos[i]=0; ypos[i]=0; } //TUTORIAL PT 1 initializing array of mouse positions for (int i=0; i<xpos1.length; i++) { xpos1[i]=80; ypos1[i]=300; }

f = createFont("Dotum-20.vlw", 20, true);

}

void draw() { if (screen==1) {

instructions();

}

if (screen==3) {

Submit();

}

if (screen==4) { background(255); text("This is the first level. I'll make this at some point", 200, 200); } }

void mousePressed() { mouseIsDown = true; }

//this function is called every time you release a mouse button void mouseReleased() { mouseIsDown = false; }

void Submit () {

print("the following text was submitted :"); url1 = cp5.get(Textfield.class, "textInput_1").getText(); //url2 = cp5.get(Textfield.class, "textInput_2").getText(); print(" textInput 1 = " + url1); //print(" textInput 2 = " + url2); println();

}`


Viewing all articles
Browse latest Browse all 2896

Trending Articles