ok so far so good, now when i want some kind of breakout clone, how can i manage collision and visibility for each brick?
i dont know how to manage more than 3 objects ^^
does anyone know maybe a good site with example code?
I suppose you'll need an array of some sort of sf::Sprites, I'm not sure which you want to implement but for break out its only like 64 bricks? So it
really does not matter (for this anyways). Pseudo-code is as follows:
const int WindowX = 800;
const int WindowY = 600;
//Assuming your window goes from 0,0 to 800,600
sf::Sprite Bricks[64] = {...} // I assume you'd set there position somewhere
int InView(sf::Sprite& Arg)
{
//compare to window view
if(Arg.X > WindowX || Arg.X <0)
return 0;
if(Arg.Y > WindowY || Arg.Y < 0)
return 0;
if(Arg.Y < WindowY && Arg.Y > 0)
return 1;
if(Arg.X < WindowX && Arg.X > 0)
return 1;
}
//... somewhere in render-loop
for(int i = 0; i <= 64; i++) //++i?
{
if(InView(Bricks[i]))
{
//draw
}
}
Didn't try to check if it was correct or anything, but if it is outside of the window range it should not draw it. Coincidentally you can rewrite InView to be Collision(int X, int Y, sf::Sprite& Arg) it will compare the X,Y you provide to the position of the object and see if they collide...