|
Nokia N97 SDK Example Applications Guide |
#include <sprite.h>
Inheritance diagram for CSprite:
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 |
|
|
~CSprite Virtual Destructor. Definition at line 82 of file sprite.cpp.
|
|
||||||||||||||||||||||||
|
CSprite Perform the first phase of two phase construction.
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 }
|
|
||||||||||||||||||||||||
|
NewL. Two-phased constructor. Create a CSprite object.
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 }
|
|
||||||||||||||||||||||||
|
NewLC. Two-phased constructor. Create a CSprite object.
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 }
|
|
|
Position Return the position of the sprite on the screen.
Definition at line 87 of file sprite.h. References iPosition. Referenced by CGraphicsAppView::UpdateDisplay(). 00087 { return iPosition; }
|
|
|
Image
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); }
|
|
|
Mask
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); }
|
|
||||||||||||
|
Move Move the sprite.
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 }
|
|
||||||||||||
|
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.
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 }
|
|
|
ConstructL 2nd phase constructor. Perform the second phase construction of a CSprite object. Definition at line 92 of file sprite.cpp. Referenced by Mask().
|
|
|
iPosition Definition at line 151 of file sprite.h. Referenced by Adjust(), Move(), and Position(). |
|
|
iXVelocity Definition at line 156 of file sprite.h. Referenced by Move(). |
|
|
iYVelocity Definition at line 161 of file sprite.h. Referenced by Move(). |
|
|
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(). |
|
|
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(). |
|
© Nokia 2009 |