ManaPlus
Public Member Functions | Private Attributes
ImageSprite Class Reference

#include <imagesprite.h>

Inheritance diagram for ImageSprite:
Sprite

Public Member Functions

 ImageSprite (Image *const image)
 
 ~ImageSprite ()
 
bool reset ()
 
bool play (const std::string &action)
 
bool update (const int time)
 
void draw (Graphics *const graphics, const int posX, const int posY) const
 
int getWidth () const
 
int getHeight () const
 
const ImagegetImage () const
 
bool setSpriteDirection (const SpriteDirection::Type direction)
 
int getNumberOfLayers () const
 
unsigned int getCurrentFrame () const
 
unsigned int getFrameCount () const
 
bool updateNumber (const unsigned num)
 
- Public Member Functions inherited from Sprite
virtual ~Sprite ()
 
virtual void setAlpha (float alpha)
 
virtual float getAlpha () const
 
virtual const void * getHash () const
 
virtual const void * getHash2 () const
 

Private Attributes

ImagemImage
 

Additional Inherited Members

- Protected Member Functions inherited from Sprite
 Sprite ()
 
- Protected Attributes inherited from Sprite
float mAlpha
 

Detailed Description

Definition at line 32 of file imagesprite.h.

Constructor & Destructor Documentation

◆ ImageSprite()

ImageSprite::ImageSprite ( Image *const  image)
explicit

Definition at line 29 of file imagesprite.cpp.

29  :
30  mImage(image)
31 {
32  if (mImage != nullptr)
33  {
34  mAlpha = mImage->mAlpha;
35  mImage->incRef();
36  }
37  else
38  {
39  mAlpha = 1;
40  }
41 }
Image * mImage
Definition: imagesprite.h:80
float mAlpha
Definition: sprite.h:130

References Sprite::mAlpha, and mImage.

◆ ~ImageSprite()

ImageSprite::~ImageSprite ( )

Definition at line 43 of file imagesprite.cpp.

44 {
45  if (mImage != nullptr)
46  {
47  mImage->decRef();
48  mImage = nullptr;
49  }
50 }

References mImage.

Member Function Documentation

◆ draw()

void ImageSprite::draw ( Graphics *const  graphics,
const int  posX,
const int  posY 
) const
virtual

Draw the current animation frame at the coordinates given in screen pixels.

Implements Sprite.

Definition at line 52 of file imagesprite.cpp.

54 {
55  FUNC_BLOCK("ImageSprite::draw", 1)
56  if (mImage == nullptr)
57  return;
58 
60  graphics->drawImage(mImage, posX, posY);
61 }
virtual void setAlpha(float alpha)
Definition: sprite.h:97
if(!vert) return
void drawImage(const Image *restrict const image, int dstX, int dstY) restrict2 override final
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:81

References Graphics::drawImage(), FUNC_BLOCK, Sprite::mAlpha, and mImage.

◆ getCurrentFrame()

unsigned int ImageSprite::getCurrentFrame ( ) const
inlinevirtual

Returns the current frame number for the sprite.

Implements Sprite.

Definition at line 70 of file imagesprite.h.

71  { return 0; }

◆ getFrameCount()

unsigned int ImageSprite::getFrameCount ( ) const
inlinevirtual

Returns the frame count for the sprite.

Implements Sprite.

Definition at line 73 of file imagesprite.h.

74  { return 1; }

◆ getHeight()

int ImageSprite::getHeight ( ) const
inlinevirtual

Gets the height in pixels of the image of the current frame

Implements Sprite.

Definition at line 57 of file imagesprite.h.

58  { return mImage != nullptr ? mImage->getHeight() : 0; }

References mImage.

◆ getImage()

const Image* ImageSprite::getImage ( ) const
inlinevirtual

Returns a reference to the current image being drawn.

Implements Sprite.

Definition at line 60 of file imagesprite.h.

61  { return mImage; }

References mImage.

◆ getNumberOfLayers()

int ImageSprite::getNumberOfLayers ( ) const
inline

Definition at line 67 of file imagesprite.h.

68  { return 1; }

◆ getWidth()

int ImageSprite::getWidth ( ) const
inlinevirtual

Gets the width in pixels of the image of the current frame

Implements Sprite.

Definition at line 54 of file imagesprite.h.

55  { return mImage != nullptr ? mImage->getWidth() : 0; }

References mImage.

◆ play()

bool ImageSprite::play ( const std::string &  action)
inlinevirtual

Plays an action using the current direction.

Returns
true if the sprite changed, false otherwise

Implements Sprite.

Definition at line 44 of file imagesprite.h.

45  { return false; }

◆ reset()

bool ImageSprite::reset ( )
inlinevirtual

Resets the sprite.

Returns
true if the sprite changed, false otherwise

Implements Sprite.

Definition at line 41 of file imagesprite.h.

42  { return false; }

◆ setSpriteDirection()

bool ImageSprite::setSpriteDirection ( const SpriteDirection::Type  direction)
inlinevirtual

Sets the direction.

Returns
true if the sprite changed, false otherwise

Implements Sprite.

Definition at line 63 of file imagesprite.h.

65  { return false; }

◆ update()

bool ImageSprite::update ( const int  time)
inlinevirtual

Inform the animation of the passed time so that it can output the correct animation frame.

Returns
true if the sprite changed, false otherwise

Implements Sprite.

Definition at line 47 of file imagesprite.h.

48  { return false; }

◆ updateNumber()

bool ImageSprite::updateNumber ( const unsigned  num)
inlinevirtual

Implements Sprite.

Definition at line 76 of file imagesprite.h.

77  { return false; }

Field Documentation

◆ mImage

Image* ImageSprite::mImage
private

Definition at line 80 of file imagesprite.h.

Referenced by draw(), getHeight(), getImage(), getWidth(), ImageSprite(), and ~ImageSprite().


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