Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
This page was last modified 20:12, 15 December 2007.

Implementing Animation using CAknBitmapAnimation

From Forum Nokia Wiki

Contents

Introduction

This example below shows simple animation in application code using CAknBitmapAnimation api. CAknBitmapAnimation class provides an interface to an animation DLL, hence we only need to provide it with some Images and Attribute Data.


The important part of the animation example are the Frames ( Images ) which completes the animation sequence.

What is required

Three essential resources are needed to construct an animation

1) Bitmap Animation Data.
2) Array of bitmap frames.
3) Bitmap Images.

Bitmap Animation Data

It is the Resource defining the animation to be used by CAknBitmapAnimation.


RESOURCE BMPANIM_DATA r_animation_data
	{
		// Represents delay between frames
 
		frameinterval = 400;
 
	
		// There are three play mode available
 
                /*
		1) EAknBitmapAnimationPlayModePlay :
			play once
		2) EAknBitmapAnimationPlayModeCycle :  
			repeat from the first frame to the last.   
                3) EAknBitmapAnimationPlayModeBounce :
			play the first frame to the last and then back down to 
                        the first, repeatedly. */
 
 
		playmode = EAknBitmapAnimationPlayModeBounce;
 
		// Represents Flashing is On or Off.
 
		flash = 0;
 
		// The .mbm file containing the animation frame.
 
		bmpfile = ANIMATION_BMPFILE_NAME;
 
		
		// Reference to the ARRAY resource of BMPANIM_FRAME definitions.
 
		frames = r_animation_array ;
	}


The ANIMATION_BMPFILE_NAME is the .mbm (Multi-Bitmap file) and creating .mbm file is the preferred way of using bitmaps and accessing the bitmaps runtime.

Hence you need to specifiy the .mbm file name and the bitmaps to be included, this file is generated by the compiler.

Below is the code in .mmp file for generating .mbm file. Specify all the images to be used in the animation. This files are by default stored at \system\apps\applicationname folder\

START BITMAP Animation.mbm
HEADER
SOURCEPATH ..\Images
SOURCE C12 DisplayImageFrame1.bmp
SOURCE C12 DisplayImageFrame2.bmp
SOURCE C12 DisplayImageFrame3.bmp
SOURCE C12 DisplayTextFrame.bmp
END


The IDs are generated into the mbg file. The bitmaps can be accessed from the mbm file with this ID number. Each ID number is constructed automatically and is in the following format: EMbm<MBM file name><bitmap file name>, for example, EMbmMygameImage1.


Array of bitmap frames.

This is the Array of BMPANIM_FRAME elements that will be used by BMPANIM_DATA and finally CAknBitmapAnimation.


RESOURCE ARRAY r_animation_array
{
	items = 
	{
	// time  : represents time that frame is displayed for.
	// bmpid : ID from of the desired bitmap from the .mbm file for this frame.
 
	BMPANIM_FRAME {	time = 200; bmpid = EMbmAnimationDisplayimageframe1;},
	BMPANIM_FRAME {	time = 200; bmpid = EMbmAnimationDisplayimageframe2;},
	BMPANIM_FRAME {	time = 200; bmpid = EMbmAnimationDisplayimageframe3;},
	BMPANIM_FRAME {	time = 200; bmpid = EMbmAnimationDisplayimageframe1;},
	BMPANIM_FRAME {	time = 200; bmpid = EMbmAnimationDisplayimageframe2;},
	BMPANIM_FRAME {	time = 200; bmpid = EMbmAnimationDisplayimageframe3;},
	BMPANIM_FRAME {	time = 1000; bmpid = EMbmAnimationDisplaytextframe; }
	};
}


Bitmap Images

This bitmaps are the images ( frames ) that in sequence creates the animation.


Using the prepared Resources

Once all the required resources are prepare, we are ready for preparing animation control.

In the Header file include

#include <aknbitmapanimation.h> 
 
//Forward Declaration
class CAknBitmapAnimation;

Inside the Container Class

CAknBitmapAnimation* iAnimation;

And do not forget to include

 #include <BARSREAD.h>

This header file is required by "TResourceReader"


Now in the cpp file

// instantiate CAknBitmapAnimation
 
iAnimation = CAknBitmapAnimation::NewL();
 
 
// creating a TResourceReader object for reading the resource.
 
TResourceReader reader;
 
// map resource to resource reader
 
iCoeEnv->CreateResourceReaderLC(reader, R_ANIMATION_DATA); 
 
 
// provide animation control with animation data
 
iAnimation->ConstructFromResourceL(reader);
 
// animation control needs a window
 
iAnimation->SetContainerWindowL(*this);
 
// starts the animation.
 
iAnimation->StartAnimationL(); 
 
// Pop and Destroy the resource reader 
 
CleanupStack::PopAndDestroy();

Canceling Animation

iAnimation->CancelAnimation();


bmconv tool

Bitmaps provide the pixel patterns used by pictures, icons and masks, sprites and brush styles for filling areas of the display. To optimize bitmap performance, Symbian OS uses files containing multiple bitmaps in its own highly compressed format. A tool is provided (bmconv.exe) with the S60 SDK that takes one or more Windows bitmap (.bmp) files as input and generates a single Symbian OS multi-bitmap file (.mbm), optimized for efficient runtime loading.


The bmconv tool also generates a header file (.mbg) with symbolic definitions (identifiers) for each bitmap in the file. This generated header file is placed in the \epoc32\include folder of the SDK. It is intended for inclusion (#include) in your C++ code to allow you to reference any of the individual bitmaps as required.


Two types of .mbm files are possible, file store bitmap files that are loaded into RAM and ROM image bitmap files that do not use any RAM when being accessed—only system developers normally create ROM-based .mbm files.


During the conversion process it is possible to specify the number of bits per pixel for the converted bitmaps and whether they should be color or grayscale. The program can also split Symbian OS multi-bitmap (.mbm) files back into component bitmap files in Windows bitmap (.bmp) format.


You do not always have to use the bmconv tool directly to produce bitmap files that are dedicated to a particular application. Building the required bitmaps can be performed as part of the standard abld project building process. A list of .bmp files can be specified in the project definition (.mmp) file. The above example shows statements in the project definition (.mmp) file using START BITMAP syntax.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Implementing Dialogs in 7650 Nokia_Archive General Symbian C++ 2 2002-05-29 16:10
Creating Race Tracks rajatram Mobile Java Games 0 2006-11-29 09:27
Problem implementing Seperate delivery arch123 Digital Rights Management & Content Downloading 5 2007-05-14 09:10
tick() corpuschaos Mobile Java General 4 2004-06-17 04:36
Smile File not shown correctly in MMS Presentation jensbardel General Messaging 0 2006-01-18 14:49
 
Powered by MediaWiki
RDF Facets: qfnZtopicQUqfnTopicZanimationQ qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX