We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › HELP w/ Fireball : cursor or bar won't draw
Page Index Toggle Pages: 1
HELP w/ Fireball : cursor or bar won't draw (Read 412 times)
HELP w/ Fireball : cursor or bar won't draw
Aug 22nd, 2008, 3:22pm
 
Hello to you all programmers Cheesy ,

I am currently creating a little program that makes a fireball with a tail go around the screen and bouncing. Now I want to add cursors at the bottom to change the different characteristics of the ball : speed, size ... so I created a specific class, called Curs (for cursor), and the different values to be changed depend on its position.

I've tried with one so far : horizontal speed. Here is the problem : it's not visible Sad . If you go the bottom left of the screen, imagine a button there and drag it along, the speed will be modified as it should (I ran a couple numerical values tests using the println() method), but the cursor is nowhere to be seen, nor the line that should represent the bar on which it slides. Any idea ? Thanks in advance Wink !

Oh, and here's the code (if the error, which is probably quite stupid, is not here, give me your email and I'll send you the whole thing) :

//Boolean telling wether the mouse is dragged. It is set to true with mouseDragged and false with mouseReleased
boolean dragging = false;

//Creating the cursors and setting them depending on the already-existing values that they will later modify.
Curs cXspeed = new Curs(map(xspeed,-15,15,50,250),650,50, 250);

// The cursor class
class Curs {
    float xpos, ypos, xmin, xmax;
    float width = 300; // SInce the cursor is invisible, width is set to 300 to be easily dragged although not visible, for testing purposes
    boolean mouseOver = false;
    //The cursor takes in 4 values : its orignal x value, its y value (which will remain the same throughout, since it only slides left and right), and its x limits (how far it can be moved from left to right)
    Curs(float x, float y, float min, float max){
         xpos = x;
         ypos = y;
         xmin = min;
         xmax = max;
    }
    // The main method of the Curs class, ran every frame in draw()
    void update(){

         fill(0);
         stroke(0);
        // The one big if statement, that tells if the mouse is within the bounds of the cursor and if so, changes it's sides' color
         if((mouseX > (xpos-width/2)) && (mouseX < (xpos+width/2)) && (mouseY > (ypos-width/2)) && (mouseY < (ypos+width/2))){
              stroke(255);
              mouseOver = true;
               //println("updating...");
         }
         // Change the color if the mouse is pressed and over the cursor
         if(mouseOver && mousePressed){
              stroke(0);
              fill(255);
         }
         // Moves the cursor if the mouse is over it and dragged, but constrain its position between its x (left and right) limits
         if(mouseOver && dragging){
              xpos = constrain(mouseX, xmin, xmax);
         }
         // And finally, the cursor is drawn on top of its bar
         strokeWeight(3);
         line(xmin,ypos,xmax,ypos);
         strokeWeight(1);
         rectMode(CENTER);
         rect(xpos,ypos, width, width);
    }
}

//The method that checks for mouse dragging
void mouseDragged(){
    dragging = true;
}
// The method that checks for mouse releasing and sets "dragging" to false
void mouseReleased(){
    dragging = false;
}

//Function that updates the values depending on their corresponding cursor's position
void updateValues(){
    xspeed = map(cXspeed.xpos, cXspeed.xmin, cXspeed.xmax, 0, 15);
    if(backing){ //If, in its current direction, the fireball's speed is negative, and since the updated value is always positive, we need to set it to negative.
         xspeed = -xspeed;
    }
}

Re: HELP w/ Fireball : cursor or bar won't draw
Reply #1 - Aug 22nd, 2008, 3:33pm
 
didt check your code but maybe you wanna give this great GUI Library a try...

http://www.sojamo.de/libraries/controlP5/
Re: HELP w/ Fireball : cursor or bar won't draw
Reply #2 - Aug 22nd, 2008, 4:09pm
 
Alright thanks I'll give it a look Wink . Anything else ?
Page Index Toggle Pages: 1