More theoretical fixes to the scroller. I didn't repro this on win, but I had a couple of cases on my psp - I suspect that the missing reset on the currentID counter was causing problems should the task list shrink after a duel. Also added a modulus calculation to make sure that we never go outside the bounds of the string vector.
This commit is contained in:
@@ -39,6 +39,7 @@ void TextScroller::Add(string text){
|
||||
|
||||
void TextScroller::Reset(){
|
||||
strings.clear();
|
||||
currentId = 0;
|
||||
}
|
||||
|
||||
void TextScroller::Update(float dt){
|
||||
@@ -54,7 +55,7 @@ void TextScroller::Update(float dt){
|
||||
currentId = (rand() % strings.size());
|
||||
}else{
|
||||
currentId++;
|
||||
if (currentId > strings.size()-1)currentId = 0;
|
||||
if (currentId >= strings.size())currentId = 0;
|
||||
}
|
||||
mText = strings[currentId];
|
||||
}
|
||||
@@ -68,7 +69,8 @@ void TextScroller::Update(float dt){
|
||||
size_t nbItemsToDisplay = ( minimumItems < strings.size() ? minimumItems : strings.size());
|
||||
for ( size_t idx = 0; idx < nbItemsToDisplay; ++idx)
|
||||
{
|
||||
scrollerText << strings[currentId + idx];
|
||||
size_t index = (currentId + idx) % strings.size();
|
||||
scrollerText << strings[index];
|
||||
}
|
||||
currentId++;
|
||||
if ( currentId >= strings.size())
|
||||
|
||||
Reference in New Issue
Block a user