hey im wondering if this is efficient for say, writing a game like "breakOut"?
Or should one strive for using tilemaps instead of allocating many sf::RectangleShapes?
Say i would want to add some texture to the rectShapes, would this be really inefficient in the long run?
#define SFML_STATIC
#define WIN32_LEAN_AND_MEAN
#include "SFML\Graphics.hpp"
float vel = 0.02f;
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
window.setFramerateLimit(60);
sf::RectangleShape tiles[10][10];
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
tiles[i][j].setPosition(sf::Vector2f((i * 10), ((j * 10) + 20)));
tiles[i][j].setSize(sf::Vector2f(5, 5));
tiles[i][j].setFillColor(sf::Color(20*i, 40, 140, 255));
}
}
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
tiles[i][j].move(sf::Vector2f(1.0f, 0.0f));
}
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
tiles[i][j].move(sf::Vector2f(-1.0f, 0.0f));
}
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
tiles[i][j].move(sf::Vector2f(0.0f, -1.0f));
}
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
tiles[i][j].move(sf::Vector2f(0.0f, 1.0f));
}
}
}
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
window.draw(tiles[i][j]);
}
}
window.display();
}
return 0;
}