Calling draw() doesn't draw shapes it from other functions?

I want to update a position without using update() through test() and after updating i want to call draw() to change the position of the circle drawn but the problem is the function draw() is called from test() but the position of circle is not changed .I’ve had already done it using update() and boolean but i need to do it the following way.

void ofApp::draw(){
	ofDrawCircle(pos, 20);
}

void ofApp::test()
{

	while (pos.x < 500)
	{
		pos.x++;
		pos.y++;
		draw();
		this_thread::sleep_for(chrono::milliseconds(200));
	}
}

void ofApp::keyPressed(int key){
	if (key == 'r')
	{
		test();
	}
}

Hi, well, @freak,

I’m not exactly an expert on openFrameworks, but how I understand it, update() and draw() run each frame, no matter what (except maybe when looping is turned off).
Calling draw() thus seems pretty redundant, since all you do is redraw what already has been drawn.

Could you maybe explain what you’re trying to achieve, the bigger picture I mean?

Currently, if nothing moves, you probably aren’t pressing the R key, or the x of your pos is already bigger than or equal to 500, or the while loop is still running sluggishly, because your pausing at each iteration for 2 seconds?

Hi @freak , draw() gets called internally by OF, so if you call it will have no effect. Then, remove that sleep you have there cause it will make everything run much worse.
All this is actually a lot simpler than all that.


//put the following line in your ofApp.h file, inside the ofApp declaration.

bool testing = false;

void ofApp::draw(){
	if(testing && pos.x < 500)
	{
		pos.x++;
		pos.y++;
	}
	else
	{
		testing = false;
	}
	ofDrawCircle(pos, 20);
}

void ofApp::keyPressed(int key){
	if (key == 'r')
	{
		if(testing == false)
		{ 
			testing = true;
		}
	}
}