[英]Basic animation doesn't fire
I'm trying to follow this example to create an animation: 我正在尝试按照以下示例创建动画:
http://seriss.com/people/erco/fltk/#Animate http://seriss.com/people/erco/fltk/#Animate
Except for the fact that instead of changing the image I'm moving it. 除了不移动图像而是移动图像。 There's a car image that should move in a down-right direction every half second, for 10 times:
有一个汽车图像应每半秒沿右下方向移动10次:
void func(void* data)
{
static int counter=0;
counter++;
Fl_PNG_Image* image= static_cast<Fl_PNG_Image*>(data);
Fl_Box* box= new Fl_Box(counter*10, counter*10,100,100);
box->image(image);
//delete box;
window->redraw();
if(counter==10)
{
Fl::remove_timeout(func,data);
}
else
{
Fl::repeat_timeout(.5,func,data);
}
}
int main(int argc, char **argv)
{
window = new Fl_Double_Window(width, height);
Fl_PNG_Image* image= new Fl_PNG_Image("car-down.png");
Fl_Box* box= new Fl_Box(0,0,100,100);
box->image(image);
Fl::add_timeout(.5, func, image);
//delete box;
window->end();
window->show(argc, argv);
return Fl::run();
}
I have two problems: 我有两个问题:
Instead of creating new boxes and images, move the box. 而不是创建新的框和图像,而是移动框。 The box will be deleted when the window is closed
关闭窗口后,该框将被删除
void func(void* data)
{
static int counter=0;
counter++;
//Fl_PNG_Image* image= static_cast<Fl_PNG_Image*>(data);
Fl_Box* box= static_cast<Fl_Box*) data;
box->position(counter*10, counter*10);
window->redraw();
...
}
int main(int argc, char **argv)
{
...
Fl::add_timeout(.5, func, box);
window->end();
window->show(argc, argv);
return Fl::run();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.