addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwchatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgoogleimageimagesinstagramlinklocation-pinmagnifying-glassmailminusmoremuplabelShape 3 + Rectangle 1outlookpersonplusprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

XNA 4.0 Primitives -- IndexList

public class IndexList : List
{
protected int index;
protected bool wrap;

public T Current
{
get {
if (Count == 0) return default(T);
return this[index];
}
}

public bool Wrap {
get { return wrap; }
}

public int GetIndex(Predicate locator)
{
var target = FindIndex(locator);
if (target >= 0) index = target;
return target;
}

public void MoveNext()
{
wrap = false;
if (Count < 2) return;
index++;
if (index < Count) return;
index = 0;
wrap = true;
}

public void Move(int index)
{
if (Count == 0) return;
this.index = index.Clamp(0, Count - 1);
}

public void MovePrevious()
{
wrap = false;
if (Count < 2) return;
index--;
if (index >= 0) return;
index = Count - 1;
wrap = true;
}
}

I spent some time looking over custom enumerators but the ones I found had lists or IList objects built-in. I think it better to add an index into a collection class than the reverse.

Table of Contents

Page title Most recent update Last edited by
Friends of Boston Windows Game Developers November 5, 2014 9:22 AM Jeffrey S.
XNA 4.0 Primitives -- IndexList January 31, 2012 11:57 AM David W.
XNA 4.,0 Services -- Random January 31, 2012 10:54 AM David W.
XNA 4.0 Services -- Input January 31, 2012 10:45 AM David W.
XNA 4.0 Extension Methods February 14, 2012 9:51 PM David W.
About Boston Windows Game Developers January 5, 2012 7:10 AM Michael C.

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy