Nokia N97 SDK
Example Applications Guide

CSprite Class Reference

#include <sprite.h>

Inheritance diagram for CSprite:

List of all members.

Detailed Description

CSprite. An instance of class CSprite represents an object being displayed on the screen

Definition at line 32 of file sprite.h.


Public Member Functions

virtual  ~CSprite ()
TPoint  Position () const
CFbsBitmap *  Image () const
CFbsBitmap *  Mask () const
void  Move (const TSize &aSize, const TRect &aBounds)
void  Adjust (const TSize &aSize, const TRect &aBounds)

Static Public Member Functions

static CSprite *  NewL (TInt aXVelocity, TInt aYVelocity, const TPoint &aInitialPosition, CFbsBitmap *aImage, CFbsBitmap *aMask)
static CSprite *  NewLC (TInt aXVelocity, TInt aYVelocity, const TPoint &aInitialPosition, CFbsBitmap *aImage, CFbsBitmap *aMask)

Private Member Functions

  CSprite (TInt aXVelocity, TInt aYVelocity, const TPoint &aInitialPosition, CFbsBitmap *aImage, CFbsBitmap *aMask)
void  ConstructL ()

Private Attributes

TPoint  iPosition
TInt  iXVelocity
TInt  iYVelocity
const CFbsBitmap *const  iImage
const CFbsBitmap *const  iMask


Constructor & Destructor Documentation

CSprite::~CSprite (   )  [virtual]
 

~CSprite Virtual Destructor.

Definition at line 82 of file sprite.cpp.

00083     {
00084     // No implementation required
00085     }

CSprite::CSprite (  TInt  aXVelocity,
TInt  aYVelocity,
const TPoint &  aInitialPosition,
CFbsBitmap *  aImage,
CFbsBitmap *  aMask
)  [private]
 

CSprite Perform the first phase of two phase construction.

Parameters:
aXVelocity  The velocity of the sprite on the x axis.
aYVelocity  The velocity of the sprite on the y axis.
aInitialPosition  The starting position of the sprite on the screen.
aImage  pointer to the image represented by this sprite. Note that ownershiup of the image is not taken.
aMask  pointer to the mask of the image represented by this sprite. Note that ownershiup of the mask is not taken.

Definition at line 26 of file sprite.cpp.

Referenced by Mask(), and NewLC().

00031 :   iPosition( aInitialPosition ),
00032     iXVelocity( aXVelocity ),
00033     iYVelocity( aYVelocity ),
00034     iImage(aImage),
00035     iMask(aMask)
00036     {
00037     // No implementation required
00038     }


Member Function Documentation

CSprite * CSprite::NewL (  TInt  aXVelocity,
TInt  aYVelocity,
const TPoint &  aInitialPosition,
CFbsBitmap *  aImage,
CFbsBitmap *  aMask
)  [static]
 

NewL. Two-phased constructor. Create a CSprite object.

Parameters:
aXVelocity  The velocity of the sprite on the x axis.
aYVelocity  The velocity of the sprite on the y axis.
aInitialPosition  The starting position of the sprite on the screen.
aImage  pointer to the image represented by this sprite. Note that ownershiup of the image is not taken.
aMask  pointer to the mask of the image represented by this sprite. Note that ownershiup of the mask is not taken.
Returns:
A pointer to the created instance of CSprite.

Definition at line 45 of file sprite.cpp.

References NewLC().

00050     {
00051     CSprite* self = NewLC( aXVelocity,aYVelocity,aInitialPosition,aImage,aMask );
00052     CleanupStack::Pop( self );
00053     return self;
00054     }

CSprite * CSprite::NewLC (  TInt  aXVelocity,
TInt  aYVelocity,
const TPoint &  aInitialPosition,
CFbsBitmap *  aImage,
CFbsBitmap *  aMask
)  [static]
 

NewLC. Two-phased constructor. Create a CSprite object.

Parameters:
aXVelocity  The velocity of the sprite on the x axis.
aYVelocity  The velocity of the sprite on the y axis.
aInitialPosition  The starting position of the sprite on the screen.
aImage  pointer to the image represented by this sprite. Note that ownershiup of the image is not taken.
aMask  pointer to the mask of the image represented by this sprite. Note that ownershiup of the mask is not taken.
Returns:
A pointer to the created instance of CSprite.

Definition at line 61 of file sprite.cpp.

References CSprite().

Referenced by NewL(), and CGraphicsAppView::SetUpSpritesL().

00066     {
00067     CSprite* self = new ( ELeave ) CSprite( aXVelocity,
00068                                             aYVelocity,
00069                                             aInitialPosition,
00070                                             aImage,
00071                                             aMask );
00072     CleanupStack::PushL( self );
00073     self->ConstructL();
00074     return self;
00075     }

TPoint CSprite::Position (   )  const [inline]
 

Position Return the position of the sprite on the screen.

Returns:
The position

Definition at line 87 of file sprite.h.

References iPosition.

Referenced by CGraphicsAppView::UpdateDisplay().

00087 { return iPosition; }

CFbsBitmap* CSprite::Image (   )  const [inline]
 

Image

Returns:
pointer to the image represented by this sprite.

Definition at line 93 of file sprite.h.

References iImage.

Referenced by CGraphicsAppView::DoPeriodTask(), CGraphicsAppView::HandleResourceChange(), and CGraphicsAppView::UpdateDisplay().

00093 { return const_cast<CFbsBitmap*>(iImage); }

CFbsBitmap* CSprite::Mask (   )  const [inline]
 

Mask

Returns:
pointer to the image mask represented by this sprite.

Definition at line 99 of file sprite.h.

References Adjust(), ConstructL(), CSprite(), iMask, and Move().

Referenced by CGraphicsAppView::UpdateDisplay().

00099 { return const_cast<CFbsBitmap*>(iMask); }

void CSprite::Move (  const TSize &  aSize,
const TRect &  aBounds
) 
 

Move Move the sprite.

Parameters:
aSize  The size of the sprite
aBounds  The rectangle the sprite is allowed to move in

Definition at line 102 of file sprite.cpp.

References iPosition, iXVelocity, and iYVelocity.

Referenced by CGraphicsAppView::DoPeriodTask(), and Mask().

00103     {
00104     TBool okToMove = ETrue;
00105 
00106     // Calculate the new sprite position
00107     TPoint newPostion = iPosition + TPoint( iXVelocity,iYVelocity );
00108 
00109     // Check that the new sprite X position is not out of bounds
00110     TInt width = aSize.iWidth;
00111     TInt leftX = newPostion.iX;
00112     TInt rightX = newPostion.iX + width;
00113     if ( ( rightX > aBounds.iBr.iX ) || ( leftX < aBounds.iTl.iX ) )
00114         {
00115         // If it is, "bounce" the sprite off the edge of the boundary
00116         iXVelocity = -iXVelocity;
00117         // and don't let it move this tick
00118         okToMove = EFalse;
00119         }
00120 
00121     // Check that the new sprite Y position is not out of bounds
00122     TInt height = aSize.iHeight;
00123     TInt topY = newPostion.iY;
00124     TInt bottomY = newPostion.iY + height;
00125     if ( ( bottomY > aBounds.iBr.iY ) || ( topY < aBounds.iTl.iY ) )
00126         {
00127         // If it is, "bounce" the sprite off the edge of the boundary
00128         iYVelocity = -iYVelocity;
00129         // and don't let it move this tick
00130         okToMove = EFalse;
00131         }
00132 
00133     // If the sprite can move this tick
00134     if ( okToMove )
00135         {
00136         // Move it
00137         iPosition = newPostion;
00138         }
00139     }

void CSprite::Adjust (  const TSize &  aSize,
const TRect &  aBounds
) 
 

Adjust If resolution or orientation of the screen has changed, the current position may be out of bounds. In suc case a new position within the rectangle is set.

Parameters:
aSize  The size of the sprite
aBounds  The rectangle the sprite is allowed to move in

Definition at line 146 of file sprite.cpp.

References iPosition.

Referenced by CGraphicsAppView::HandleResourceChange(), and Mask().

00147     {
00148     // check if right and bottom extremities are within the rect
00149     TPoint pos = iPosition + TPoint( aSize.iWidth, aSize.iHeight );
00150     if (!aBounds.Contains(pos))
00151         {
00152         // we have to adjust the position
00153         if (pos.iX > aBounds.iBr.iX)
00154             iPosition.iX = aBounds.iBr.iX - aSize.iWidth;
00155 
00156         if (pos.iY > aBounds.iBr.iY)
00157             iPosition.iY = aBounds.iBr.iY - aSize.iHeight;
00158         }
00159     }

void CSprite::ConstructL (   )  [private]
 

ConstructL 2nd phase constructor. Perform the second phase construction of a CSprite object.

Definition at line 92 of file sprite.cpp.

Referenced by Mask().

00093     {
00094     // No implementation required
00095     }


Member Data Documentation

TPoint CSprite::iPosition [private]
 

iPosition

Definition at line 151 of file sprite.h.

Referenced by Adjust(), Move(), and Position().

TInt CSprite::iXVelocity [private]
 

iXVelocity

Definition at line 156 of file sprite.h.

Referenced by Move().

TInt CSprite::iYVelocity [private]
 

iYVelocity

Definition at line 161 of file sprite.h.

Referenced by Move().

const CFbsBitmap* const CSprite::iImage [private]
 

iImage The "sprite" bitmap image. Not owned. This is just a reference so that the user of the sprite can get the pointer to the image represented by this sprite.

Definition at line 169 of file sprite.h.

Referenced by Image().

const CFbsBitmap* const CSprite::iMask [private]
 

iMask The "sprite" bitblit mask Not owned. This is just a reference so that the user of the sprite can get the pointer to the image represented by this sprite.

Definition at line 177 of file sprite.h.

Referenced by Mask().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top