Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to create a basic animation

The animation framework provides a concrete implementation of the CAnimation class called CBasicAnimation class to create a basic client-side animation. A basic client-side animation needs data, which can range from a simple file to a complex data structure. The data provider is responsible for handling this data and cater to the needs of the animation whenever required. The CICLAnimationDataProvider class acts as a data provider and handles the data needed for any type of animation.

To create a basic client-side animation, create an object of the CICLAnimationDataProvider class. Associate the data required for the animation with the data provider object. In the example used below, the data needed for the animation is a simple animated GIF file.

The following code shows how to create a data provider object and associate a GIF file with it:

//Path to the GIF file
_LIT(KAnimExGuitarPlayer,"Z:\\resource\\apps\\AnimExample\\GuitarPlayer.gif");

//Creating the data provider object and setting the GIF file using the string literal created above.
//The iEikonEnv macro is used to open a session with the file system, before setting the GIF file to the data provider. 
CICLAnimationDataProvider* basicDataProvider = new (ELeave)CICLAnimationDataProvider;
basicDataProvider->SetFileL(iEikonEnv->FsSession(), KAnimExGuitarPlayer());

Now that the data provider object is ready with the required data, you can create an object of CBasicAnimation class. The control and behaviour for the animation is defined using the TAnimationConfig class. You should create such an object and provide it to the animation. The behaviour of the animation can be set to any of the following:

In this case, the animation is configured to play in an infinite loop.

The following code shows how to create and start a basic client-side animation. It loads an animated GIF file and plays it in an infinite loop :

//Integer constant defining the X and Y co-ordinates of the animation
const TInt KAnimExBasicPositionX = 300;
const TInt KAnimExBasicPositionY = 100;
TPoint position = TPoint(KAnimExBasicPositionX, KAnimExBasicPositionY);

//configure the animation to play in an infinite loop
TAnimationConfig config;
config.iFlags = TAnimationConfig::ELoop;
config.iData = -1;

//Creating the basic animation object using the data provider object and the X and Y coordinates defined above
iBasicAnim = CBasicAnimation::NewL(basicDataProvider,position, iEikonEnv->WsSession(), Window());        

//Starting the animation using the configuration created above
iBasicAnim->Start(config);

The animation will be visible only when it is rendered to the window. To do so, implement a private virtual member function of CCoeControl class called Draw() in your client application view class. This function should in-turn call the CBasicAnimation::Draw function by passing the windows graphics context as an argument.

The following code shows how to draw the animation to the window:

void CClientAppView::Draw(const TRect&) const
{
    
    CWindowGc& gc = SystemGc();  
    if( iBasicAnim )
        {
        iBasicAnim->Draw( gc );    
        }
}

Note that you should include proper error checks in the given code before using it for production.

When a new frame is required for the animation, the entire window or an area within in the window need to be redrawn using the RWindow::Invalidate() function. This function will force a client redraw.

This code creates a client-side animation which loads an animated GIF file and plays it in an infinite loop.

[Top]


See also