On 04/28/2010 12:22 PM, Sparkaround wrote:
>>
>
> Yes, I want to control some 2D sprites with mouse or keyboard in real time
> and interact with the fast animation in real time as fast as I can. It seemed
> that this is not easy to implement in fltk.
>
Along with all the good advice you've gotten from the developers, I'd
like to add one other thing which should speed things up a bit.
Your timer callback should update the position of your sprites. This
should not be done in the drawing code. This allows screen redraws to
be combined when the processor gets busy, making for smoother and faster
sprite movement which is independent of how long the drawing code takes.
I learned this one a few years back while learning SDL, but find it
works no matter what gui toolkit you use.
Here is your original test code modified to show this.
HTH
Mike
---
#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>
#define DELAY 0.0001
class Test_Draw: public Fl_Widget
{
public:
static double d;
Test_Draw(int x, int y, int w, int h, char *l=0)
:Fl_Widget(x,y,w,h,l)
{}
void draw(){
fl_rectf(x(),y(), (int) d%w(), (int)d%h(), 255,255,255);
}
};
double Test_Draw::d= 0.0;
Test_Draw *t;
static void update(void *)
{
if(Fl::event_key('a')) exit(0);
Fl::add_timeout(DELAY, update, 0);
Test_Draw::d+= 0.01;
t->redraw();
}
int main(int argc, char **argv)
{
Fl_Double_Window w(200,200,Fl::w()/2, Fl::h()/2);
//Fl_Window w(200,200,Fl::w()/2, Fl::h()/2);
t = new Test_Draw(0,0,w.w(),w.h());
w.end();
w.show(argc, argv);
Fl::add_timeout(DELAY, update, 0);
Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk