ManaPlus
Public Member Functions | Static Public Attributes
ImageParticle Class Reference

#include <imageparticle.h>

Inheritance diagram for ImageParticle:
Particle Actor AnimationParticle RotationalParticle

Public Member Functions

 ImageParticle (Image *const image)
 
void draw (Graphics *const graphics, const int offsetX, const int offsetY) const
 
void setAlpha (const float alpha)
 
- Public Member Functions inherited from Particle
 Particle ()
 
 ~Particle ()
 
void clear ()
 
bool update ()
 
void draw (Graphics *const graphics, const int offsetX, const int offsetY) const
 
int getPixelY () const
 
int getSortPixelY () const
 
ParticleaddEffect (const std::string &particleEffectFile, const int pixelX, const int pixelY, const int rotation)
 
void addEmitter (ParticleEmitter *const emitter)
 
void moveTo (const Vector &pos)
 
void moveTo (const float x, const float y)
 
void moveBy (const Vector &change)
 
void setLifetime (const int lifetime)
 
void setFadeOut (const int fadeOut)
 
void setFadeIn (const int fadeIn)
 
void setVelocity (const float x, const float y, const float z)
 
void setGravity (const float gravity)
 
void setRandomness (const int r)
 
void setBounce (const float bouncieness)
 
void setFollow (const bool follow)
 
bool doesFollow () const
 
void setDestination (Particle *const target, const float accel, const float moment)
 
void setDieDistance (const float dist)
 
void adjustEmitterSize (const int w, const int h)
 
void setAllowSizeAdjust (const bool adjust)
 
bool isAlive () const
 
void prepareToDie ()
 
bool isExtinct () const
 
void kill ()
 
void disableAutoDelete ()
 
int getNumberOfLayers () const
 
float getAlpha () const
 
void setAlpha (const float alpha)
 
virtual void setDeathEffect (const std::string &effectFile, const signed char conditions)
 
void setActor (const BeingId actor)
 
- Public Member Functions inherited from Actor
virtual ~Actor ()
 
virtual int getWidth () const
 
virtual int getHeight () const
 
const VectorgetPixelPositionF () const
 
virtual void setPixelPositionF (const Vector &pos)
 
int getPixelX () const
 
virtual int getTileX () const
 
virtual int getTileY () const
 
virtual void setMap (Map *const map)
 
const MapgetMap () const
 

Static Public Attributes

static StringIntMap imageParticleCountByName
 

Additional Inherited Members

- Data Fields inherited from Actor
int mPixelX
 
int mPixelY
 
- Protected Member Functions inherited from Particle
void updateSelf ()
 
- Protected Member Functions inherited from Actor
 Actor ()
 
- Protected Attributes inherited from Particle
float mAlpha
 
int mLifetimeLeft
 
int mLifetimePast
 
int mFadeOut
 
int mFadeIn
 
Vector mVelocity
 
AliveStatusT mAlive
 
ParticleTypeT mType
 
SimpleAnimationmAnimation
 
ImagemImage
 
BeingId mActor
 
- Protected Attributes inherited from Actor
MapmMap
 
Vector mPos
 
int mYDiff
 

Detailed Description

A particle that uses an image for its visualization.

Definition at line 35 of file imageparticle.h.

Constructor & Destructor Documentation

◆ ImageParticle()

ImageParticle::ImageParticle ( Image *const  image)
explicit

Constructor. The image is reference counted by this particle.

Parameters
imagean Image instance, may not be NULL

Definition at line 33 of file imageparticle.cpp.

33  :
34  Particle()
35 {
37  mImage = image;
38  if (mImage != nullptr)
39  {
40  mImage->incRef();
41 
42  const std::string &restrict name = mImage->mIdPath;
47  else
48  (*it).second ++;
49  }
50 }

References ParticleType::Image, imageParticleCountByName, Resource::incRef(), Resource::mIdPath, Particle::mImage, Particle::mType, and restrict.

Member Function Documentation

◆ draw()

void ImageParticle::draw ( Graphics *const  graphics,
const int  offsetX,
const int  offsetY 
) const
virtual

Draws the particle image

Implements Actor.

Definition at line 52 of file imageparticle.cpp.

55 {
56  FUNC_BLOCK("ImageParticle::draw", 1)
57  if (mAlive != AliveStatus::ALIVE || (mImage == nullptr))
58  return;
59 
60  const int w = mImage->mBounds.w;
61  const int h = mImage->mBounds.h;
62  const int screenX = CAST_S32(mPos.x)
63  + offsetX - w / 2;
64  const int screenY = CAST_S32(mPos.y) - CAST_S32(mPos.z)
65  + offsetY - h / 2;
66 
67  // Check if on screen
68  if (screenX + w < 0 ||
69  screenX > graphics->mWidth ||
70  screenY + h < 0 ||
71  screenY > graphics->mHeight)
72  {
73  return;
74  }
75 
76  float alphafactor = mAlpha;
77 
78  if ((mFadeOut != 0) && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
79  {
80  alphafactor *= static_cast<float>(mLifetimeLeft)
81  / static_cast<float>(mFadeOut);
82  }
83 
84  if ((mFadeIn != 0) && mLifetimePast < mFadeIn)
85  {
86  alphafactor *= static_cast<float>(mLifetimePast)
87  / static_cast<float>(mFadeIn);
88  }
89 
90  mImage->setAlpha(alphafactor);
91  graphics->drawImage(mImage, screenX, screenY);
92 }

References AliveStatus::ALIVE, CAST_S32, FUNC_BLOCK, and anonymous_namespace{mrand.cpp}::mPos.

◆ setAlpha()

void ImageParticle::setAlpha ( const float  alpha)
inlinevirtual

Sets the alpha value used to draw the actor.

Implements Actor.

Definition at line 55 of file imageparticle.h.

56  { mAlpha = alpha; }

References Particle::mAlpha.

Field Documentation

◆ imageParticleCountByName

StringIntMap ImageParticle::imageParticleCountByName
static

The documentation for this class was generated from the following files:
Actor::mPos
Vector mPos
Definition: actor.h:139
Particle::mType
ParticleTypeT mType
Definition: particle.h:270
Image::setAlpha
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
Particle::mFadeIn
int mFadeIn
Definition: particle.h:262
Resource::incRef
virtual void incRef()
Definition: resource.cpp:37
if
if(!vert) return
ImageParticle::imageParticleCountByName
static StringIntMap imageParticleCountByName
Definition: imageparticle.h:58
FUNC_BLOCK
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:80
Particle::mAlive
AliveStatusT mAlive
Definition: particle.h:268
ParticleType::Image
@ Image
Definition: particletype.h:30
x
x
Definition: graphics_calcImageRect.hpp:72
Particle::mLifetimeLeft
int mLifetimeLeft
Definition: particle.h:253
AliveStatus
Definition: alivestatus.h:28
Particle::mFadeOut
int mFadeOut
Definition: particle.h:259
StringIntMapIter
StringIntMap::iterator StringIntMapIter
Definition: stringmap.h:28
Particle::mAlpha
float mAlpha
Definition: particle.h:250
restrict
#define restrict
Definition: localconsts.h:164
Particle::mLifetimePast
int mLifetimePast
Definition: particle.h:256
Particle::mImage
Image * mImage
Definition: particle.h:276
CAST_S32
#define CAST_S32
Definition: cast.h:29
Graphics::drawImage
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
y
y
Definition: graphics_calcImageRect.hpp:72
InputCondition::ALIVE
@ ALIVE
Definition: inputcondition.h:46
Particle::Particle
Particle()
Definition: particle.cpp:58
Resource::mIdPath
std::string mIdPath
Definition: resource.h:83