From e0803d8066297368d55b297089257a7e857b368a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 31 Mar 2011 23:52:13 +0300 Subject: Add repeat attribute to xml sequence tag. --- src/resources/spritedef.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 8c13c595c..ceefac845 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -245,7 +245,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, } else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence")) { - int start = XML::getProperty(frameNode, "start", -1); + const int start = XML::getProperty(frameNode, "start", -1); const int end = XML::getProperty(frameNode, "end", -1); if (start < 0 || end < 0) @@ -254,20 +254,33 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, continue; } - while (end >= start) + int repeat = XML::getProperty(frameNode, "repeat", 1); + + if (repeat < 1) { - Image *img = imageSet->get(start + variant_offset); + logger->log1("No valid value for 'repeat'"); + continue; + } - if (!img) + while (repeat > 0) + { + int pos = start; + while (end >= pos) { - logger->log("No image at index %d", - start + variant_offset); - start++; - continue; + Image *img = imageSet->get(pos + variant_offset); + + if (!img) + { + logger->log("No image at index %d", + pos + variant_offset); + pos ++; + continue; + } + + animation->addFrame(img, delay, offsetX, offsetY); + pos ++; } - - animation->addFrame(img, delay, offsetX, offsetY); - start++; + repeat --; } } else if (xmlStrEqual(frameNode->name, BAD_CAST "end")) -- cgit v1.2.3-70-g09d2