|
|
Michael,
I might be misunderstanding the problem but if you only want to move the
sprite every 200ms then one idea is tp schecule a recurring timer for
~200msec and hook that QTimer's timeout() to a slot that did
sprite->move(x,y);
canvas->update(); // I'm unsure as to which method to call on the model to
let the view know things have changed, this was a guess.
This will have the nice side effect that your GUI will not freeze. It has
the downside that the moves are only going to be as realtime as the
eventloop....
I do not know if your movement is linear, but there is also the case of
using the setAdvancePeriod(ms) with a sprite->setVelocity(dx,dy). Where
the deltas are "Pixels Per Advance". So your sprite could move dx,dy
every 200ms with this combination without any intervention on your part.
This is also serviced by the eventloop, so once again not garanteed to be
200msec.
-Justin
> In my project I have a QCanvasView with several sprites on it. Four of
> the sprites will need to be moving during the run of the program. I'm
> translating this project from Java. In the Java version I would move
> the sprite and then issue Thread.sleep(200) (make the program sleep for
> 200 milliseconds so that the user could see that the sprite had moved)
> and then move the sprite again and reissue the Thread.sleep(200). I was
> considering using the sleep function included in unistd.h, but I thought
> I'd ask here to see if there was a Qt solution that might work better...
>
|
|