summaryrefslogtreecommitdiff
path: root/src/compoundsprite.h
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-05-20 01:35:17 -0600
committerJared Adams <jaxad0127@gmail.com>2010-05-20 12:25:37 -0600
commit487a86fe7dc9904f445d91667095f641f72f7c81 (patch)
tree57191d175f7b2fe771f6b2da225bc2d9cb5ff1d9 /src/compoundsprite.h
parent36832f3a5378f739da7040f0711b7101dbc2af02 (diff)
downloadmana-487a86fe7dc9904f445d91667095f641f72f7c81.tar.gz
mana-487a86fe7dc9904f445d91667095f641f72f7c81.tar.bz2
mana-487a86fe7dc9904f445d91667095f641f72f7c81.tar.xz
mana-487a86fe7dc9904f445d91667095f641f72f7c81.zip
Buffer layered sprites under SDL
This improves framerate and allows transparent overlay for complex sprites. Two copies of the buffer are kept, one at full opacity, one with variable opactiy, to reduce calls to setAlpha. Reviewed-by: Bertram
Diffstat (limited to 'src/compoundsprite.h')
-rw-r--r--src/compoundsprite.h50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/compoundsprite.h b/src/compoundsprite.h
index b3925216..c714c34b 100644
--- a/src/compoundsprite.h
+++ b/src/compoundsprite.h
@@ -25,18 +25,20 @@
#include <vector>
-class CompoundSprite : public Sprite, public std::vector<Sprite*>
+class Image;
+
+class CompoundSprite : public Sprite, private std::vector<Sprite*>
{
public:
CompoundSprite();
~CompoundSprite();
- virtual void reset();
+ virtual bool reset();
- virtual void play(SpriteAction action);
+ virtual bool play(SpriteAction action);
- virtual void update(int time);
+ virtual bool update(int time);
virtual bool draw(Graphics* graphics, int posX, int posY) const;
@@ -50,18 +52,40 @@ public:
*/
virtual int getHeight() const;
- virtual Image* getImage() const;
+ virtual const Image* getImage() const;
- virtual void setDirection(SpriteDirection direction);
+ virtual bool setDirection(SpriteDirection direction);
- virtual Sprite *getSprite(int index) const
- { return at(index); }
+ int getNumberOfLayers() const;
- int getNumberOfLayers()
- { return size(); }
-};
+ size_t size() const
+ { return std::vector<Sprite*>::size(); }
+
+ void addSprite(Sprite* sprite);
+
+ void setSprite(int layer, Sprite* sprite);
+
+ Sprite *getSprite(int layer) const
+ { return at(layer); }
+
+ void removeSprite(int layer);
+
+ void clear();
-typedef CompoundSprite::iterator SpriteIterator;
-typedef CompoundSprite::const_iterator SpriteConstIterator;
+ void ensureSize(size_t layerCount);
+
+private:
+ typedef CompoundSprite::iterator SpriteIterator;
+ typedef CompoundSprite::const_iterator SpriteConstIterator;
+
+ void redraw() const;
+
+ mutable Image *mImage;
+ mutable Image *mAlphaImage;
+
+ mutable int mOffsetX, mOffsetY;
+
+ mutable bool mNeedsRedraw;
+};
#endif // COMPOUNDSPRITE_H