Nokia N97 SDK
Example Applications Guide

sprite.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : sprite.h
00004 *  Part of     : Graphics
00005 *  Interface   :
00006 *  Description :
00007 *  Version     :
00008 *
00009 *  Copyright (c) 2004 - 2006 Nokia Corporation.
00010 *  This material, including documentation and any related
00011 *  computer programs, is protected by copyright controlled by
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 #ifndef __SPRITE_H__
00017 #define __SPRITE_H__
00018 
00019 // INCLUDES
00020 #include <e32base.h>
00021 
00022 // FORWARD DECLARATIONS
00023 class CFbsBitmap;
00024 
00025 // CLASS DECLARATION
00026 
00027 /**
00028 * CSprite.
00029 * An instance of class CSprite represents an object
00030 * being displayed on the screen
00031 */
00032 class CSprite : public CBase
00033     {
00034     public: // Constructors and destructors
00035 
00036         /**
00037         * NewL.
00038         * Two-phased constructor.
00039         * Create a CSprite object.
00040         * @param aXVelocity The velocity of the sprite on the x axis.
00041         * @param aYVelocity The velocity of the sprite on the y axis.
00042         * @param aInitialPosition The starting position of the sprite
00043         * on the screen.
00044         * @param aImage pointer to the image represented by this sprite.
00045         *   Note that ownershiup of the image is not taken.
00046         * @param aMask pointer to the mask of the image represented by this
00047         *   sprite. Note that ownershiup of the mask is not taken.
00048         * @return A pointer to the created instance of CSprite.
00049         */
00050         static CSprite* NewL( TInt aXVelocity,
00051                               TInt aYVelocity,
00052                               const TPoint& aInitialPosition,
00053                               CFbsBitmap* aImage,
00054                               CFbsBitmap* aMask );
00055         /**
00056         * NewLC.
00057         * Two-phased constructor.
00058         * Create a CSprite object.
00059         * @param aXVelocity The velocity of the sprite on the x axis.
00060         * @param aYVelocity The velocity of the sprite on the y axis.
00061         * @param aInitialPosition The starting position of the sprite
00062         * on the screen.
00063         * @param aImage pointer to the image represented by this sprite.
00064         *   Note that ownershiup of the image is not taken.
00065         * @param aMask pointer to the mask of the image represented by this
00066         *   sprite. Note that ownershiup of the mask is not taken.
00067         * @return A pointer to the created instance of CSprite.
00068         */
00069         static CSprite* NewLC( TInt aXVelocity,
00070                                TInt aYVelocity,
00071                                const TPoint& aInitialPosition,
00072                                CFbsBitmap* aImage,
00073                                CFbsBitmap* aMask );
00074         /**
00075         * ~CSprite
00076         * Virtual Destructor.
00077         */
00078         virtual ~CSprite();
00079 
00080     public: // New functions
00081 
00082         /**
00083         * Position
00084         * Return the position of the sprite on the screen.
00085         * @return The position
00086         */
00087         TPoint Position() const { return iPosition; }
00088 
00089         /**
00090         * Image
00091         * @return pointer to the image represented by this sprite.
00092         */
00093         CFbsBitmap* Image() const { return const_cast<CFbsBitmap*>(iImage); }
00094 
00095         /**
00096         * Mask
00097         * @return pointer to the image mask represented by this sprite.
00098         */
00099         CFbsBitmap* Mask() const { return const_cast<CFbsBitmap*>(iMask); }
00100 
00101         /**
00102         * Move
00103         * Move the sprite.
00104         * @param aSize The size of the sprite
00105         * @param aBounds The rectangle the sprite is allowed to move in
00106         */
00107         void Move( const TSize& aSize, const TRect& aBounds );
00108 
00109         /**
00110         * Adjust
00111         * If resolution or orientation of the screen has changed, the current
00112         * position may be out of bounds. In suc case a new position within the
00113         * rectangle is set.
00114         * @param aSize The size of the sprite
00115         * @param aBounds The rectangle the sprite is allowed to move in
00116         */
00117         void Adjust( const TSize& aSize, const TRect& aBounds );
00118 
00119     private: // Constructors
00120 
00121         /**
00122         * CSprite
00123         * Perform the first phase of two phase construction.
00124         * @param aXVelocity The velocity of the sprite on the x axis.
00125         * @param aYVelocity The velocity of the sprite on the y axis.
00126         * @param aInitialPosition The starting position of the sprite
00127         * on the screen.
00128         * @param aImage pointer to the image represented by this sprite.
00129         *   Note that ownershiup of the image is not taken.
00130         * @param aMask pointer to the mask of the image represented by this
00131         *   sprite. Note that ownershiup of the mask is not taken.
00132         */
00133         CSprite( TInt aXVelocity,
00134                  TInt aYVelocity,
00135                  const TPoint& aInitialPosition,
00136                  CFbsBitmap* aImage,
00137                  CFbsBitmap* aMask );
00138 
00139         /**
00140         * ConstructL
00141         * 2nd phase constructor.
00142         * Perform the second phase construction of a CSprite object.
00143         */
00144         void ConstructL();
00145 
00146     private: // Data
00147 
00148         /**
00149         * iPosition
00150         */
00151         TPoint iPosition;
00152 
00153         /**
00154         * iXVelocity
00155         */
00156         TInt iXVelocity;
00157 
00158         /**
00159         * iYVelocity
00160         */
00161         TInt iYVelocity;
00162 
00163         /**
00164         * iImage
00165         * The "sprite" bitmap image.
00166         * Not owned. This is just a reference so that the user of the sprite
00167         * can get the pointer to the image represented by this sprite.
00168         */
00169         const CFbsBitmap * const iImage;
00170 
00171         /**
00172         * iMask
00173         * The "sprite" bitblit mask
00174         * Not owned. This is just a reference so that the user of the sprite
00175         * can get the pointer to the image represented by this sprite.
00176         */
00177         const CFbsBitmap * const iMask;
00178     };
00179 
00180 #endif // __SPRITE_H__
00181 
00182 // End of File

© Nokia 2009

Back to top