The rendering cycle (or rendering kernel) is one of three important running stages of UI Thread.
When rendering cycle is running, it repeatedly repaint the application content as fast as possible. Every one repainting generates one frame, if the application content changes in each frame, the animation effect is generated.
When application is "still" and thus it does not needs animation, there is no need to keep rendering cycle running. In this case, the rendering cycle is paused and application does not repaint itself until the following things happen:
The application content is contained inside OGCanvas , the solid implementation of the rudimentary abstract class Window . The figure shows the hierarchical structure of Pooka SDK® application:
If at least one visible OGCanvas (implementation of Window) is detected as animating, then the application keeps the rendering cycle running.
If none of visible OGCanvas (implementation of Window) is detected as animating, then the application pauses the rendering cycle.
See Window::startAnimation()
See Window::stopAnimation()
See Window::isAnimating()
See Window::visible
Animation is one of most important function that an interactive application provides. Some applications may be mainly a "still" application, some others such as real-time games or multi-media applications are heavily relied on animation. OGCanvas provides all functions needed to play, stop and fine control animation at run-time. When animation is not play, application content appear to be still.
Regardless of the platform, the essence of animation is simply rendering application content continuously and change the animated part of content in each rendering cycle. A single rendering result is usually referred to as an "animation frame". Animation logic needs to be performed between each two animation frames to make the content animated.
Using OGCanvas to generate animation is the recommended way for most of cases, however there are two more alternative solutions to generate animation, each has its own appropriate use case. The following chart illustrate the all three animation mechanisms available for Pooka SDK® application:
| Animation Type | Definition | Implementation |
|---|---|---|
| Continuing Animation | Continuing animation lasts for long time or even runs throughout the application life-cycle. Example: a real-time game application, a video player | Implemented by OGCanvas Sample Project Spinning Cube |
| Transient Animation | Transient animation is a one-time animation and lasts only for a short period of time. Example: a page transition, or a game piece sliding from one cell into a new cell on game board. | Implemented by a ScheduledTask . See Application::postTask() for more details. Sample Project Animation |
| Thread-driven Animation | Thread-driven animation is the animation driven by a worker thread. This type of animation is started, stopped and managed by the thread and best fit in multi-threading scenarios. Example: showing an animating "waiting" cursor while retrieving remote data asynchronously. | Implemented by Thread Sample Project Animation |
There are several sample projects that can help developers understand the concept of animation in Pooka SDK® application. One of them, the Spinning Cube Sample Project, is a very simple application shows a 3D colored cube spinning along the Y-axis. This animation is implemented by the following steps.
We construct the 3D scene in OGCanvas::templateOnLoad() , once the content is ready, we call function Window::startAnimation() to make the OGCanvas animating.
To make cube appear to be spinning, we spin it by a small amount of angle in virtual function OGCanvas::animationPreRender()
We print the FPS rate in the virtual function OGCanvas::animationPostRender()
Since low-priority task is the task that does not need to be executed in every animation frame, we do it in the virtual function OGCanvas::animationIdleTask() . In this sample, we accumulate the total running time and display it from time to time.
In the event listener function, we let the animation running by Window::startAnimation() or stopped by Window::stopAnimation() .