1
General / [SOLVED ]Do calculations after window.clear(), is it bad?
« on: February 24, 2017, 01:29:40 pm »
Hi,
so I did a small code for do a sort of tilemap, that uses an std::vector of a class that inherits of sf::Sprite. So basically, a
But I have to draw this tilemap in the constructor, where other operations are done. So I am basically doing this:
This is my till class, that inherits of sf::Sprite.
So my question is, is it bad, to do things beetween window.clear and window.display, or that doesn't matter? Will that impact the framerate of the program?
Thanks
Ah, I have of course done a class for do the vector and all, TileArray:
so I did a small code for do a sort of tilemap, that uses an std::vector of a class that inherits of sf::Sprite. So basically, a
std::vector<sf::Sprite> tilemap(i, sf::Sprite(sprite));
But I have to draw this tilemap in the constructor, where other operations are done. So I am basically doing this:
window.clear(sf::Color::Cyan);
std::vector<Tile> tilemap(i, Tile(tile));
for(int a = 0; a < tilemap.size(); a++)
{
tilemap[a].setPosition(a * xpos, ypos);
}
for(int a = 0; a < tilemap.size(); a++)
{
window.draw(tilemap[a]);
}
window.draw(hero);
window.display();
std::vector<Tile> tilemap(i, Tile(tile));
for(int a = 0; a < tilemap.size(); a++)
{
tilemap[a].setPosition(a * xpos, ypos);
}
for(int a = 0; a < tilemap.size(); a++)
{
window.draw(tilemap[a]);
}
window.draw(hero);
window.display();
This is my till class, that inherits of sf::Sprite.
Tile::Tile(sf::Texture texture, int x, int y, int scalex, int scaley)
{
t = texture;
xpos = x; ypos = y; scx = scalex; scy = scaley;
this->setTexture(t);
this->setPosition(xpos, ypos);
this->setScale(scx, scy);
}
Tile::Tile()
{
}
{
t = texture;
xpos = x; ypos = y; scx = scalex; scy = scaley;
this->setTexture(t);
this->setPosition(xpos, ypos);
this->setScale(scx, scy);
}
Tile::Tile()
{
}
So my question is, is it bad, to do things beetween window.clear and window.display, or that doesn't matter? Will that impact the framerate of the program?
Thanks
Ah, I have of course done a class for do the vector and all, TileArray:
#include "TileArray.h"
TileArray::TileArray(int I, int x, int y, Tile &tile, sf::RenderWindow &window)
{
i = I;
xpos = x; ypos = y;
std::vector<Tile> tilemap(i, Tile(tile));
for(int a = 0; a < tilemap.size(); a++)
{
tilemap[a].setPosition(a * xpos, ypos);
}
for(int a = 0; a < tilemap.size(); a++)
{
window.draw(tilemap[a]);
}
}
TileArray::TileArray(int I, int x, int y, Tile &tile, sf::RenderWindow &window)
{
i = I;
xpos = x; ypos = y;
std::vector<Tile> tilemap(i, Tile(tile));
for(int a = 0; a < tilemap.size(); a++)
{
tilemap[a].setPosition(a * xpos, ypos);
}
for(int a = 0; a < tilemap.size(); a++)
{
window.draw(tilemap[a]);
}
}