diff options
author | Jared Adams <jaxad0127@gmail.com> | 2011-05-18 22:13:45 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2011-05-18 22:13:45 -0600 |
commit | 108c31241aa8074dba1b1042677b3c87f60a9600 (patch) | |
tree | 6cdc01db40845c105717f837e5e45cee5bfa7945 /src/compoundsprite.cpp | |
parent | 49b4ab9f770d776113c80936087687543b942043 (diff) | |
download | mana-108c31241aa8074dba1b1042677b3c87f60a9600.tar.gz mana-108c31241aa8074dba1b1042677b3c87f60a9600.tar.bz2 mana-108c31241aa8074dba1b1042677b3c87f60a9600.tar.xz mana-108c31241aa8074dba1b1042677b3c87f60a9600.zip |
Fix sprite caching
Diffstat (limited to 'src/compoundsprite.cpp')
-rw-r--r-- | src/compoundsprite.cpp | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 5f2c00ea..4e91d281 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -256,26 +256,24 @@ size_t CompoundSprite::getFrameCount(size_t layer) return 0; } -static void updateValues(int &dimension, int &pos, int imgDim, int imgOffset) +static void updateValues(int &dimension, int &pos, int imgDimUL, int imgDimRD, int imgOffset) { // Handle going beyond the left/up - if (imgOffset < 0) + int temp = -(pos + imgOffset - imgDimUL); // Negated for easier use + if (temp > 0) { - int temp = -(pos + imgOffset); // Negated for easier use - - if (temp > 0) - { - pos += temp; - dimension += temp; - } + pos += temp; + dimension += temp; } // Handle going beyond the right/down - int temp = pos + imgOffset + imgDim; + temp = pos + imgOffset + imgDimRD; if (temp > dimension) dimension = temp; } +#include "localplayer.h" + void CompoundSprite::redraw() const { // TODO OpenGL support @@ -300,37 +298,31 @@ void CompoundSprite::redraw() const return; } + + mWidth = mHeight = mOffsetX = mOffsetY = 0; Sprite *s = NULL; SpriteConstIterator it = begin(), it_end = end(); - for (it = begin(), it_end = end(); it != it_end; it++) - if ((s = *it)) - break; - - if (!s) - { - mWidth = mHeight = mOffsetX = mOffsetY = 0; - mNeedsRedraw = false; - return; - } - mWidth = s->getWidth(); - mHeight = s->getHeight(); - mOffsetX = s->getOffsetX(); - mOffsetY = s->getOffsetY(); - int posX = mWidth / 2; - int posY = mHeight; + int posX = 0; + int posY = 0; - for (it++; it != it_end; ++it) + for (it = begin(); it != it_end; ++it) { s = *it; if (s) { - updateValues(mWidth, posX, s->getWidth(), s->getOffsetX() - s->getWidth() / 2); - updateValues(mHeight, posY, s->getHeight(), s->getOffsetY()); + updateValues(mWidth, posX, s->getWidth() / 2, s->getWidth() / 2, s->getOffsetX()); + updateValues(mHeight, posY, s->getHeight(), 0, s->getOffsetY()); } } + if (mWidth == 0 && mHeight == 0) + { + mNeedsRedraw = false; + return; + } + mOffsetX -= posX; mOffsetY -= posY; |