BackgroundScroller.loopArray C# (CSharp) Method

loopArray() private method

private loopArray ( List sprites, int length ) : List
sprites List
length int
return List
	private List<Sprite> loopArray (List<Sprite> sprites, int length) {
		int numSprites = sprites.Count;
		List<Sprite> looped = new List<Sprite>();
		int repetitions = numSprites / length;
		int extraElements = numSprites % length;

		// Repeat sprites array. Should still work if sprites array is shorter than specified length.
		for (int i = 0; i < repetitions; i++) {
			looped.AddRange(sprites);
		}

		// Add extra elements
		looped.AddRange(new List<Sprite>(sprites.Take(extraElements)));

		return looped;               
	}