Methods affecting other methods

edited January 2016 in Library Questions

Hi there,

I have two methods, neither of which are in any classes, that seem to be affecting each other. One of them creates a sphere in the center of the screen and continuously rotates it. The other creates a text field in the upper left side of the screen. I call both of these methods in draw(). For some reason, the text field is being drawn near the sphere and rotated. When I comment out the sphere function, the textfield works perfectly. Any idea what's going on here? I've included my code below for reference. Thanks!

import g4p_controls.*; import controlP5.*;

PImage bg; PImage planet; PShape globe; Table t2; celestialObject C1; float a=0.0; PFont f; String textValue = "";

void setup(){ size(1024, 576, P3D); globe= createShape(SPHERE, 110); }

void draw() { noStroke(); background(bg); buildGraphics(); buildSphere(); }

void buildSphere(){ float dirY = (mouseY / float(height) - 0.5) * 2; float dirX = (mouseX / float(width) - 0.5) * 2; colorMode(HSB, 100); directionalLight(0, 0, 99, -dirX, -dirY, -1); translate(width/1.75, height/2, 0); //how fast the object rotates. a += 0.005; if(a > TWO_PI) { a = 0.0; } rotateY(a * 2.0); shape(globe); } void buildGraphics(){

ControlP5 cp5 = new ControlP5(this); cp5.addBang("clear") .setPosition(180,150) .setSize(40,20) .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER) ;
cp5.addTextfield("Search for a celestial body") .setPosition(20,100) .setSize(200,40)

 .setFocus(true)
 .setColor(color(255,0,0))
 ;
 text(cp5.get(Textfield.class,"Search for a celestial body").getText(), 360,130);

text(textValue, 360,180); }

Answers

Sign In or Register to comment.