bar*_*rry 1 c++ openframeworks
我是一个openFrameworks新手.我正在学习基本的2D绘图,到目前为止一切都很棒.我画了一个圆圈使用:
ofSetColor(0x333333);
ofFill;
ofCircle(100,650,50);
Run Code Online (Sandbox Code Playgroud)
我的问题是如何给圆圈一个变量名,以便我可以用鼠标按下的方法操作?我试着在ofCircle之前添加一个名字
theball.ofSetColor(0x333333);
theball.ofFill;
theball.ofCircle(100,650,50);
Run Code Online (Sandbox Code Playgroud)
但得到我'theball'没有在此范围错误中声明.
正如razong指出的那样,OF不是如何工作的.OF(据我所知)为许多OpenGL提供了一个方便的包装器.因此,您应该使用OF调用来实现当前的绘图上下文(而不是考虑使用精灵对象或其他任何内容的画布).我通常将这种东西整合到我的物体中.所以,假设你有一个这样的课......
class TheBall {
protected:
ofColor col;
ofPoint pos;
public:
// Pass a color and position when we create ball
TheBall(ofColor ballColor, ofPoint ballPosition) {
col = ballColor;
pos = ballPosition;
}
// Destructor
~TheBall();
// Make our ball move across the screen a little when we call update
void update() {
pos.x++;
pos.y++;
}
// Draw stuff
void draw(float alpha) {
ofEnableAlphaBlending(); // We activate the OpenGL blending with the OF call
ofFill(); //
ofSetColor(col, alpha); // Set color to the balls color field
ofCircle(pos.x, pos.y, 5); // Draw command
ofDisableAlphaBlending(); // Disable the blending again
}
};
Run Code Online (Sandbox Code Playgroud)
好的很酷,我希望这是有道理的.现在使用此结构,您可以执行以下操作
testApp::setup() {
ofColor color;
ofPoint pos;
color.set(255, 0, 255); // A bright gross purple
pos.x, pos.y = 50;
aBall = new TheBall(color, pos);
}
testApp::update() {
aBall->update()
}
testApp::draw() {
float alpha = sin(ofGetElapsedTime())*255; // This will be a fun flashing effect
aBall->draw(alpha)
}
Run Code Online (Sandbox Code Playgroud)
快乐的编程.快乐的设计.
| 归档时间: |
|
| 查看次数: |
1469 次 |
| 最近记录: |