I wasn't disagreeing with binary. I just think I do have a better understanding of how they work. Or at least, a method they might use. I had a Introduction to C++ class the semester before that, and it was taught assuming no programming experience. It's actually for Engineering majors (my school doesn't have a path for Computer Science, but my advisor told me I have to follow a similar path to the engineers for my time at community college). Maybe that's why he wouldn't let us use other libraries, I don't know.
Either way, I have some stuff to read up on. I can't wait to tackle this and many more projects. This community seems like a great environment with helpful people that know what they'Dr talking about :)
Thank you for your replies and help. I hope I can head in the right direction fairly soon. Unfortunately, I can only do stuff in my free time. With Calc this semester, Calc2 and Physics next, and my job, it's hard to find free time.
EDIT: Nexus, it seems like you misunderstood my 2nd question. I was going on about how, currently in my very premature code, I have:
window.clear();
window.draw(background);
window.draw(statusText);
window.draw(costText);
window.draw(moneyText);
window.draw(healthText);
for(int i = 0; i < 20; i++)
window.draw(turrets[i]);
if(placeTurret)
{
window.draw(cursorCircle);
window.draw(cursor);
}
window.display();
Now, before you go about making fun of my code, I've already stated it's very premature. I like coding stuff, and then fixing it later. Making it simple at first helps me collect my thoughts better.
Anyway, my question was, I heard doing draws like that is far from ideal. I was wondering what a better approach to drawing all of this content would be? I guess you sort of answered it, I would store all my sprites inside of a vector, and then I could just call window.draw(vector)?
Anyway, my question was, I heard doing draws like that is far from ideal.
Where have you heard this? And has the source also mentioned why? Don't believe such statements without questioning them :)
The drawing as you showed it is not a problem. The only thing one might remark is that, if you have a lot of such objects to draw, it could be worth putting them into an STL container, for easier organization. But that depends on your overall design, your code isn't bad per se.
A minor thing I would change is the loop
for(int i = 0; i < 20; i++)
window.draw(turrets[i]);
First, avoid magic constants, and second, prefer iterators over indices when you iterate. Like this, it works also for containers where you don't have random access (such as linked lists).
for (std::vector<sf::Sprite> itr = turrets.begin(); itr != turrets.end(); ++itr)
window.draw(*itr);
With C++11, you can even use the range-based for loop, which simplifies the code a lot:
for (sf::Sprite& sprite : turrets)
window.draw(sprite);
I hope you consider this as well-intended advice and not making fun of your code ;)