Hi,
can anyone point me in right direction; I want individual balls to move with the slider positioned below it (presently they all move together). I can do this when not using classes and arrays , but am stuck on how you pass the slider value into the the balls xposition...
- import controlP5.*;
- ControlP5 controlP5;
- Mixball[] mixball = new Mixball[5];
- Slider[] mySlider = new Slider[5];
- int sliderValue = 200;
- void setup() {
- controlP5 = new ControlP5(this);
- size(900,400);
- smooth();
- for (int m=0 ; m<mixball.length; m ++){
- mixball[m] = new Mixball(m*160, m , 10,10);
- }
- for (int i=0 ; i<mySlider.length; i ++){
- mySlider[i] = controlP5.addSlider("sliderValue",0,200,0,i* 160+20,298,25,100);
- }
- }
- void draw() {
- background(0);
- fill(255,0,0);
- for (int m =0; m<mixball.length; m ++){
- mixball[m].display();
- mixball[m].move();
- }
- }
- class Mixball{
- int xpos;
- int ypos;
- int width;
- int height;
- Mixball(int _xpos, int _ypos, int _width, int _height){
- xpos= _xpos;
- ypos = _ypos;
- width = _width;
- height = _height;
- }
- void display(){
- ellipse (xpos+20,ypos, width, height);
- fill (255,0,0);
- }
- void move(){
- ypos = height*24-sliderValue;
- }
- }
1