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 31 of file imagesprite.h.

Constructor & Destructor Documentation

◆ ImageSprite()

ImageSprite::ImageSprite ( Image *const  image)
explicit

Definition at line 28 of file imagesprite.cpp.

References Resource::incRef(), Sprite::mAlpha, Image::mAlpha, and mImage.

28  :
29  mImage(image)
30 {
31  if (mImage != nullptr)
32  {
33  mAlpha = mImage->mAlpha;
34  mImage->incRef();
35  }
36  else
37  {
38  mAlpha = 1;
39  }
40 }
float mAlpha
Definition: image.h:212
virtual void incRef()
Definition: resource.cpp:37
Image * mImage
Definition: imagesprite.h:79
float mAlpha
Definition: sprite.h:129

◆ ~ImageSprite()

ImageSprite::~ImageSprite ( )

Definition at line 42 of file imagesprite.cpp.

References Image::decRef(), and mImage.

43 {
44  if (mImage != nullptr)
45  {
46  mImage->decRef();
47  mImage = nullptr;
48  }
49 }
Image * mImage
Definition: imagesprite.h:79
void decRef()
Definition: image.cpp:521

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 51 of file imagesprite.cpp.

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

Referenced by update().

53 {
54  FUNC_BLOCK("ImageSprite::draw", 1)
55  if (mImage == nullptr)
56  return;
57 
59  graphics->drawImage(mImage, posX, posY);
60 }
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:80
Image * mImage
Definition: imagesprite.h:79
virtual void setAlpha(float alpha)
Definition: sprite.h:96
float mAlpha
Definition: sprite.h:129

◆ getCurrentFrame()

unsigned int ImageSprite::getCurrentFrame ( ) const
inlinevirtual

Returns the current frame number for the sprite.

Implements Sprite.

Definition at line 69 of file imagesprite.h.

70  { return 0; }

◆ getFrameCount()

unsigned int ImageSprite::getFrameCount ( ) const
inlinevirtual

Returns the frame count for the sprite.

Implements Sprite.

Definition at line 72 of file imagesprite.h.

73  { 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 56 of file imagesprite.h.

References Image::getHeight(), and mImage.

57  { return mImage != nullptr ? mImage->getHeight() : 0; }
Image * mImage
Definition: imagesprite.h:79
int getHeight() const A_INLINE
Definition: image.h:122

◆ getImage()

const Image* ImageSprite::getImage ( ) const
inlinevirtual

Returns a reference to the current image being drawn.

Implements Sprite.

Definition at line 59 of file imagesprite.h.

References mImage.

60  { return mImage; }
Image * mImage
Definition: imagesprite.h:79

◆ getNumberOfLayers()

int ImageSprite::getNumberOfLayers ( ) const
inline

Definition at line 66 of file imagesprite.h.

67  { 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 53 of file imagesprite.h.

References Image::getWidth(), and mImage.

54  { return mImage != nullptr ? mImage->getWidth() : 0; }
Image * mImage
Definition: imagesprite.h:79
int getWidth() const A_INLINE
Definition: image.h:116

◆ 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 43 of file imagesprite.h.

44  { return false; }

◆ reset()

bool ImageSprite::reset ( )
inlinevirtual

Resets the sprite.

Returns
true if the sprite changed, false otherwise

Implements Sprite.

Definition at line 40 of file imagesprite.h.

41  { 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 62 of file imagesprite.h.

64  { 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 46 of file imagesprite.h.

References A_NONNULL, and draw().

47  { return false; }

◆ updateNumber()

bool ImageSprite::updateNumber ( const unsigned  num)
inlinevirtual

Implements Sprite.

Definition at line 75 of file imagesprite.h.

76  { return false; }

Field Documentation

◆ mImage

Image* ImageSprite::mImage
private

Definition at line 79 of file imagesprite.h.

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


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