hi,
I have 5 sprites with same spritesheat. The position of each sprite on the frame must be determined by a text file i have to read into my program using StreamReader. The text file is as follows:
0,-160
160,-300
320,-250
480,-320
640,-200
This is each the x and y position where the image must start to move from. Can someone help me how to read the text into my program and use it as the x and y off each sprite? please
Loading
FroglegPosted Feb 7, 2011, 7:11 AM
using System.IO;
Point[] pts = new Point[5];
public void loadPoints()
{
int count = 0;
using (StreamReader sr = new StreamReader("pts.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] str = line.Split(',');// split into 2 strings
pts[count].X = Convert.ToInt32(str[0]);
pts[count].Y = Convert.ToInt32(str[1]);
count++;// increment by 1
}
}
}
FroglegPosted Feb 7, 2011, 3:58 PM
Also check this out - may be a better way to go
http://msdn.microsoft.com/en-us/library/bb203887.aspx
Jean HPosted Feb 7, 2011, 9:18 AM
i still have a problem, i dont get it where should i add pts.txt.
It keeps giving me error file not found.
Must i add it to the content, or specify the directory
using (StreamReader sr = new StreamReader(@"e:\\pts.txt"))