2

The basic idea is to have some animated widgets that sit in a container, quite similar to Qt (the only actual difference is that my widgets are animated).

The animation is in some cases dependent on the current "time" (e.g. frame number) and it has some "events". To better explain this, let's take for example a line. To create an interesting effect, I may want in the first 100 frames to have the line "growing" from left to right, and then to stay still. So the line animation is basically split into an intro and the main loop.

The problem is how to build the architecture of this animation/event handling? My current approach is to have a class Animated that keeps track of time (it has a counter incremented each time the widget is redrawn - basically at each frame). Also, it has some methods that set up the events of the animation (i.e. for 100 frames, intro, then the main loop) and some which increment the frame counter and retrieve the current event. The events are stored in an array and they have a name/id and a duration (so getting the current event is quite easy, based on the current frame number). Then, I have widgets which inherit Animated, and when they are drawn, they check the current event and take specific action.

I don't mind the fact that the animation is defined in this way by the object itself, but I do not like the Animated class, since basically each object has a different "clock". Also, I would like to be able to control the animation of each widget (i.e. be able to shorten/lengthen the duration of the events). In the current approach, I can do this, but I must setup the events from the exterior (the main issue is that I need to know the name of the events and their meaning).

Is there a better way of doing this?

1

If you use frame numbers as reference, your animation may run faster or slower, depending how good the PC is.

A better approach would be to have timed events, and to update your animation depending on these.

By the way, in qt it is possible to do whatever you like. Animated widgets are easy to do. Handle a timer event, and do custom paining of the widget. Qt provides all kind of events you can imagine.

0

Why you would even begin to implement this is beyond me. Qt has such a tools for such animations in place already for both its widgets and qml (qml side being slightly more convenient imo). If qt is not possible, there is probably numerous other libraries.

  • This looks more like a comment than an answer... – Christophe Jul 21 '16 at 13:04
0

Sounds like a state machine to me. Create a set of events and have the end of one start the beginning of the next one. The line growing would be a state (with state of its own representing the current length), then the full length line (maybe pulsating or something) would be another state. Then, maybe an event would then trigger a "close" even where the line shrinks back down. But it's just a list of queued states that are transitioned between as they 'expire' or an external event triggers a change to another one.

Also, as others have said, don't use frame count, use actual system clock time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.