1
Graphics / GetPosition() and arrays of shapes
« on: November 29, 2008, 01:32:00 am »
I was trying to make a scrolling grid using an array shape::lines and ran into a problem when tring to call GetPosition() on each line in the array. It seems to only get the position of the whole array or the first shape in the array as the grid only loops when the first line gets to the bottom and not when each line gets to the bottom. I can just track my own y coords and make it work but am wondering why GetPosition doesn't seem to work with arrays or if I'm doing something wrong in my code (besides passing ints instead of floats...):
Setup:
In main loop:
Setup:
Code: [Select]
//Create background lines
int backX[7] = {0,100,200,300,400,500,600};
int backY[8] = {0,100,200,300,400,500,600,700};
sf::Shape backLinesV[7];
sf::Shape backLinesH[8];
for (int i = 0; i < 7; i++)
backLinesV[i] = sf::Shape::Line(backX[i],0,backX[i],winY,2,sf::Color(128,128,128));
for (int i = 0; i < 8; i++)
backLinesH[i] = sf::Shape::Line(0,backY[i],winX,backY[i],2,sf::Color(128,128,128));
In main loop:
Code: [Select]
//Background lines
for (int i = 0; i < 7; i++)
win.Draw(backLinesV[i]);
for (int i = 0; i < 8; i++)
{
win.Draw(backLinesH[i]);
sf::Vector2f Position = backLinesH[i].GetPosition();
if (Position.y >= 0 && Position.y <= winY)
backLinesH[i].Move(0,1);
else
backLinesH[i].SetPosition(0,0);
}