Hello to you all programmers
,
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
. 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
!
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;
}
}