dxf::Sprite Class Reference

#include <dxf_sprite.h>

List of all members.

Public Member Functions

 Sprite ()
HRESULT CreateFromFile (const std::wstring &filename, D3DCOLOR transparent=0)
HRESULT CreateFromTexture (const Texture &texture)
void Unload ()
void Render2D ()
void Render2D (const D3DXVECTOR2 &position)
unsigned GetWidth () const
unsigned GetHeight () const
D3DXVECTOR2 GetAbsoluteCenter () const
D3DXVECTOR2 GetScaling () const
void SetPosition (int x, int y)
void SetPosition (const D3DXVECTOR2 &position)
void SetScaling (float x, float y)
void SetScaling (const D3DXVECTOR2 &scaling)
void SetRotationCenter (const D3DXVECTOR2 &rotationCenter)
void SetRotationCenterAsCenter ()
void SetRotation (const float &rotation)
void SetColor (D3DCOLOR color)
bool CheckIntersection (const POINT &p)
TextureGetTexture ()
IDirect3DTexture9 * GetD3DTexture ()
HRESULT SetAnimationParameters (int count, int cols, int rows)
void SetAnimation (int frame)
void Animate ()

Private Member Functions

HRESULT Init ()
void UpdateRect ()

Private Attributes

Texture texture
bool destroyTexture
int rows
int cols
RECT rect
int frame
int count
D3DXVECTOR2 position
D3DXVECTOR2 scaling
D3DXVECTOR2 rotationCenter
float rotation
D3DCOLOR color


Detailed Description

Sprites are pretty much everything on the screen in 2D games and applications.

Definition at line 36 of file dxf_sprite.h.


Constructor & Destructor Documentation

dxf::Sprite::Sprite (  ) 

Definition at line 34 of file dxf_sprite.cpp.

References color, position, rotation, rotationCenter, and scaling.


Member Function Documentation

void dxf::Sprite::Animate (  ) 

Set the current animation frame to be the next frame, from left to right then down a row.

Definition at line 107 of file dxf_sprite.cpp.

References count, frame, and UpdateRect().

bool dxf::Sprite::CheckIntersection ( const POINT &  p  ) 

Check to see if the point p is inside of the sprite

Definition at line 199 of file dxf_sprite.cpp.

References dxf::checkIntersection(), GetHeight(), GetWidth(), position, and scaling.

HRESULT dxf::Sprite::CreateFromFile ( const std::wstring &  filename,
D3DCOLOR  transparent = 0 
)

Load the sprite from a file using the passed color as the color to use as transparent. If the sprite format has an alpha channel, the transparent color is ignored.

Parameters:
name Name of the sprite. If the name is of the format name-x-y-z.ext where x y and z are all numbers, this will automatically set the animation parameters to x = count, y = cols, z = rows. See SetAnimationParameters below.

Definition at line 42 of file dxf_sprite.cpp.

References dxf::Texture::CreateFromFile(), destroyTexture, Init(), and texture.

HRESULT dxf::Sprite::CreateFromTexture ( const Texture texture  ) 

Create the new sprite from an existing, client-owned texture.

Definition at line 50 of file dxf_sprite.cpp.

References destroyTexture, Init(), and texture.

Referenced by dxf::Console::Load().

D3DXVECTOR2 dxf::Sprite::GetAbsoluteCenter (  )  const

Get the unscaled center of the sprite. This will be the center of a frame in an animated sprite.

Definition at line 152 of file dxf_sprite.cpp.

References GetHeight(), and GetWidth().

IDirect3DTexture9 * dxf::Sprite::GetD3DTexture (  ) 

Definition at line 159 of file dxf_sprite.cpp.

References dxf::Texture::GetD3DTexture(), and texture.

unsigned dxf::Sprite::GetHeight (  )  const

Get the width and height of the sprite as it appears on the screen. If the sprite is an animation, this will be a frame height and width.

Definition at line 149 of file dxf_sprite.cpp.

References dxf::Texture::GetHeight(), rows, and texture.

Referenced by CheckIntersection(), GetAbsoluteCenter(), SetRotationCenterAsCenter(), and UpdateRect().

D3DXVECTOR2 dxf::Sprite::GetScaling (  )  const

Get the current scaling factor.

Definition at line 155 of file dxf_sprite.cpp.

References scaling.

Texture * dxf::Sprite::GetTexture (  ) 

Definition at line 163 of file dxf_sprite.cpp.

References texture.

unsigned dxf::Sprite::GetWidth (  )  const

Get the width and height of the sprite as it appears on the screen. If the sprite is an animation, this will be a frame height and width.

Definition at line 146 of file dxf_sprite.cpp.

References cols, dxf::Texture::GetWidth(), and texture.

Referenced by CheckIntersection(), GetAbsoluteCenter(), SetRotationCenterAsCenter(), and UpdateRect().

HRESULT dxf::Sprite::Init (  )  [private]

Definition at line 61 of file dxf_sprite.cpp.

References dxf::Texture::GetFilename(), SetAnimationParameters(), texture, and dxf::toint().

Referenced by CreateFromFile(), and CreateFromTexture().

void dxf::Sprite::Render2D ( const D3DXVECTOR2 &  position  ) 

Draw the sprite on the screen using the passed temporary coordinates.

Definition at line 133 of file dxf_sprite.cpp.

References color, dxf::DXFGetD3DXSprite(), dxf::Texture::GetD3DTexture(), rect, rotation, rotationCenter, scaling, and texture.

void dxf::Sprite::Render2D (  ) 

Draw the sprite on the screen using the stored position coordinates.

Definition at line 121 of file dxf_sprite.cpp.

References color, dxf::DXFGetD3DXSprite(), dxf::Texture::GetD3DTexture(), position, rect, rotation, rotationCenter, scaling, and texture.

Referenced by dxf::Console::Render2D().

void dxf::Sprite::SetAnimation ( int  frame  ) 

Set the current animation frame to the specified frame

Definition at line 101 of file dxf_sprite.cpp.

References count, and UpdateRect().

HRESULT dxf::Sprite::SetAnimationParameters ( int  count,
int  cols,
int  rows 
)

Override the animation parameters in the filename.

Parameters:
count number of animation frames in the image, can't be more than rows * cols
cols number of columns in the image, sprite width is texture width / this number
rows number of rows in the image, sprite height is texture height / this number

Definition at line 77 of file dxf_sprite.cpp.

References frame, and UpdateRect().

Referenced by Init().

void dxf::Sprite::SetColor ( D3DCOLOR  color  ) 

Set color, a white sprite will change to this color, other colors will have interesting results.

Definition at line 195 of file dxf_sprite.cpp.

Referenced by dxf::Console::Load().

void dxf::Sprite::SetPosition ( const D3DXVECTOR2 &  position  ) 

Set the x,y position of the sprite on the screen. This is the position of the upper- left pixel of the sprite.

Definition at line 171 of file dxf_sprite.cpp.

void dxf::Sprite::SetPosition ( int  x,
int  y 
)

Set the x,y position of the sprite on the screen. This is the position of the upper- left pixel of the sprite.

Definition at line 167 of file dxf_sprite.cpp.

References position.

Referenced by dxf::Console::Load().

void dxf::Sprite::SetRotation ( const float &  rotation  ) 

Set rotation in radians, positive is counterclockwise.

Definition at line 191 of file dxf_sprite.cpp.

void dxf::Sprite::SetRotationCenter ( const D3DXVECTOR2 &  rotationCenter  ) 

Set the center of rotation for the sprite, use height/2, width/2 to rotate around the center.

Definition at line 183 of file dxf_sprite.cpp.

void dxf::Sprite::SetRotationCenterAsCenter (  ) 

Set the center of rotation for the sprite, using height/2, width/2

Definition at line 187 of file dxf_sprite.cpp.

References GetHeight(), GetWidth(), and rotationCenter.

void dxf::Sprite::SetScaling ( const D3DXVECTOR2 &  scaling  ) 

Set the scaling of the sprite. This is 1, 1 for non-scaled sprites.

Definition at line 179 of file dxf_sprite.cpp.

void dxf::Sprite::SetScaling ( float  x,
float  y 
)

Set the scaling of the sprite. This is 1, 1 for non-scaled sprites.

Definition at line 175 of file dxf_sprite.cpp.

References scaling.

Referenced by dxf::Console::Load(), and dxf::Console::OnResetDevice().

void dxf::Sprite::Unload (  ) 

Definition at line 57 of file dxf_sprite.cpp.

References destroyTexture, texture, and dxf::Texture::Unload().

Referenced by dxf::Console::Unload().

void dxf::Sprite::UpdateRect (  )  [private]

Definition at line 113 of file dxf_sprite.cpp.

References cols, frame, GetHeight(), GetWidth(), and rect.

Referenced by Animate(), SetAnimation(), and SetAnimationParameters().


Member Data Documentation

D3DCOLOR dxf::Sprite::color [private]

Definition at line 144 of file dxf_sprite.h.

Referenced by Render2D(), and Sprite().

int dxf::Sprite::cols [private]

Definition at line 135 of file dxf_sprite.h.

Referenced by GetWidth(), and UpdateRect().

int dxf::Sprite::count [private]

Definition at line 138 of file dxf_sprite.h.

Referenced by Animate(), and SetAnimation().

bool dxf::Sprite::destroyTexture [private]

Definition at line 133 of file dxf_sprite.h.

Referenced by CreateFromFile(), CreateFromTexture(), and Unload().

int dxf::Sprite::frame [private]

Definition at line 137 of file dxf_sprite.h.

Referenced by Animate(), SetAnimationParameters(), and UpdateRect().

D3DXVECTOR2 dxf::Sprite::position [private]

Definition at line 140 of file dxf_sprite.h.

Referenced by CheckIntersection(), Render2D(), SetPosition(), and Sprite().

RECT dxf::Sprite::rect [private]

Definition at line 136 of file dxf_sprite.h.

Referenced by Render2D(), and UpdateRect().

float dxf::Sprite::rotation [private]

Definition at line 143 of file dxf_sprite.h.

Referenced by Render2D(), and Sprite().

D3DXVECTOR2 dxf::Sprite::rotationCenter [private]

Definition at line 142 of file dxf_sprite.h.

Referenced by Render2D(), SetRotationCenterAsCenter(), and Sprite().

int dxf::Sprite::rows [private]

Definition at line 134 of file dxf_sprite.h.

Referenced by GetHeight().

D3DXVECTOR2 dxf::Sprite::scaling [private]

Definition at line 141 of file dxf_sprite.h.

Referenced by CheckIntersection(), GetScaling(), Render2D(), SetScaling(), and Sprite().

Texture dxf::Sprite::texture [private]

Definition at line 132 of file dxf_sprite.h.

Referenced by CreateFromFile(), CreateFromTexture(), GetD3DTexture(), GetHeight(), GetTexture(), GetWidth(), Init(), Render2D(), and Unload().


The documentation for this class was generated from the following files:
Generated on Fri Aug 18 12:01:29 2006 for DXFramework by  doxygen 1.4.7