'skeezix' said:
The second image is pretty hot
How is the smoke trail done? Particle engine of sorts, using coloured sprites as fit particles and alpha blending them atop each other? (Thats how I've been experimenting of late..)
jeff
Since SDL can't really scale or rotate stuff efficiently all the alpha blending and sizing is made in the animation. Download the demo and look in the data folder (I think its the data/kaboom folder).
I wrote myself an abstraction for frame based sprites here is the header:
CODE
#ifndef SDLE_ANIMSPRITE_H
#define SDLE_ANIMSPRITE_H
#include <SDL.h>
#include <Sprite.h>
#include <ParticleSprite.h>
#include <Point.h>
#include <vector>
namespace SDLE
{
/// Animated Sprite with n Frames
class AnimSprite: public ParticleSprite
{
public:
/// class constructor
//AnimSprite();
/// class constructor
AnimSprite(SDL_Surface* member);
/// class constructor
AnimSprite(const std::vector<SDL_Surface*>& frames);
/// class destructor
virtual ~AnimSprite();
/// add one frame to the end of the sequence
void addFrame(SDL_Surface* member);
/// add frames to the end of the sequence
void addFrames(const std::vector<SDL_Surface*>& frames);
/// set animation to a defined frame
void setFrameNum(int frameNum);
/// set speed of the Animation (in animframes per frame, can be < 0.0 and negative)
void setAnimSpeed(float fpf);
/// get lenght of this animation
int getAnimLength();
/// get the frame container of this animsprite
std::vector<SDL_Surface*>& getFrames();
/// framestep
void animStep();
protected:
/// anim frames per animStep
float _fpf;
/// current frame number in float to support fpf in < 1.0
float _frameNum;
/// current frame number
int _frameNumInt;
/// pointer to the frames
std::vector<SDL_Surface*> _frames;
};
} // SDLE
#endif // SDLE_ANIMSPRITE_H
Here is the implementation:
CODE
#include <AnimSprite.h>
namespace SDLE
{
///////////////////////////////////////////////////////////////////////////////
/// class constructor
AnimSprite::AnimSprite(SDL_Surface* member):
ParticleSprite(member),
_fpf(1.0),
_frameNum(0.0),
_frameNumInt(0),
_frames()
{
_lifeTime = -1;
}
///////////////////////////////////////////////////////////////////////////////
/// class constructor
AnimSprite::AnimSprite(const std::vector<SDL_Surface*>& frames):
ParticleSprite(0),
_fpf(1.0),
_frameNum(0.0),
_frameNumInt(0),
_frames()
{
_lifeTime = -1;
addFrames(frames);
setMember(_frames[0]);
}
///////////////////////////////////////////////////////////////////////////////
/// class destructor
/* virtual */
AnimSprite::~AnimSprite()
{
//_frames.clear();
}
///////////////////////////////////////////////////////////////////////////////
/// add one frame to the end of the sequence
void
AnimSprite::addFrame(SDL_Surface* member)
{
_frames.push_back(member);
// set frame 1 for member
if (_frames.size())
{
setMember(_frames[0]);
}
}
///////////////////////////////////////////////////////////////////////////////
/// add frames to the end of the sequence
void
AnimSprite::addFrames(const std::vector<SDL_Surface*>& frames)
{
for (unsigned int i=0; i!=frames.size(); ++i)
{
_frames.push_back(frames
);
}
// set frame 1 for member
if (_frames.size())
{
setMember(_frames[0]);
}
}
///////////////////////////////////////////////////////////////////////////////
/// set animation to a defined frame
void
AnimSprite::setFrameNum(int frameNum)
{
_frameNum = frameNum;
if (_frames.size())
{
_frameNumInt = int(_frameNum) % (_frames.size());
setMember(_frames[_frameNumInt]);
}
}
///////////////////////////////////////////////////////////////////////////////
/// set speed of the animation
void
AnimSprite::setAnimSpeed(float fpf)
{
_fpf = fpf;
}
///////////////////////////////////////////////////////////////////////////////
/// set speed of the animation
int
AnimSprite::getAnimLength()
{
return _frames.size()-1;
}
///////////////////////////////////////////////////////////////////////////////
/// get the frame container of this animsprite
std::vector<SDL_Surface*>&
AnimSprite::getFrames()
{
return _frames;
}
///////////////////////////////////////////////////////////////////////////////
/// draw the sprite to a destination surface
void
AnimSprite::animStep()
{
_frameNum = _frameNum + _fpf;
if (_frames.size())
{
_frameNumInt = int(_frameNum) % (_frames.size());
setMember(_frames[_frameNumInt]);
}
}
///////////////////////////////////////////////////////////////////////////////
} // /namespace SDLE