如何使用openframeworks的draw()函數在x秒內爲x繪製一個square - ofRect(x,y,w,h)?繪圖函數定時器openframeworks
我知道這是可能的,因爲繪製使用fps,但我不知道如何操作才能做我想要的。
謝謝!
如何使用openframeworks的draw()函數在x秒內爲x繪製一個square - ofRect(x,y,w,h)?繪圖函數定時器openframeworks
我知道這是可能的,因爲繪製使用fps,但我不知道如何操作才能做我想要的。
謝謝!
一種選擇是基於時間內插,不使用ofGetElapsedTimeMillis()
另一種是使用補間/動畫附加幀計數。你可以找到相當的ofxAddons一些動畫節
你可以做的是,在最簡單的方法:
int x = ofGetElapsedTimeMillis();
int y = 10;
int w = 100;
int h = 100;
ofDrawRectangle(x, y, w, h);
注意,在你了openFrameworks應從ofRectangle使用ofDrawRectangle,it is different。
如果你想達到更adivanced動畫,我會建議你使用ofxTweenzor addon,在那裏你可以在一段時間內是這樣操作的變量:
.h文件中:
#include "ofMain.h"
#include "ofxTweenzor.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
float x1;
};
。 cpp文件:
#include "testApp.h"
void ofApp::setup() {
Tweenzor::init();
float initialX = 0.f;
float finalX = 900.f;
float delay = 0.0f;
float durationInSeconds = 1.f;
Tweenzor::add(&x, initialX, finalX, delay, durationInSeconds);
}
void ofApp::update(){
Tweenzor::update(ofGetElapsedTimeMillis());
}
void ofApp::draw() {
int y = 10;
int w = 100;
int h = 100;
ofDrawRectangle(x, y, w, h);
}