Making objects move only if the mouse is being dragged

Hello! I am trying to make an object move, only if the user is currently drawing (mouseDragged).

my ball is moving from point a to point b:

  float pctShaped =  powf(pct, 0.5);    //pct * pct;    ///powf(pct, 2);
    ofPoint mixPt = (1.0-pctShaped) * aStart + pctShaped * bEnd;
    ofSetColor(ofColor::fuchsia);
    ofCircle(mixPt, 100);

Is it just a matter of adding one line in here?

void testApp::mousePressed(int x, int y, int button){
    line.clear();
    line.addVertex(ofPoint(x,y));
    }

source code:

Thx,
Eve

Hi there!

You also have to do something like:

void ofApp::mouseDragged(int x, int y, int button){
    line.addVertex(ofPoint(x,y));
}

When you first click, you register the mousePressed(): you clear the ofPolyline and add the first vertex. Then, by dragging the mouse, you add more vertices .

Thx hubris -

Should I also add an if/else statement in the draw function for the ball moving? maybe something like this:

if (mouseDragged = true){
    float pctShaped =  powf(pct, 0.5);     //pct * pct;      ///powf(pct, 2);
    ofPoint mixPt = (1.0-pctShaped) * aStart + pctShaped * bEnd;
    ofSetColor(ofColor::fuchsia);
    ofCircle(mixPt, 100);
    }

Or are you saying that I need to add this in the void ofApp:: mouseDragged section?

Is there a good place online to read about this?

Eve

ok! I see what you mean, I just did this and it’s working. Yaay.

void ofApp::mouseDragged(int x, int y, int button){
     line.addVertex(ofPoint(x,y));
     pct += 0.005;

(I’m a super beginner :slight_smile: )