c++ - Tiles not rendering in SFML despite basically being a dressed up rectangle class -
class tile : public sf::rectangleshape { public: tile(); tile(float); ~tile(); void highlighttile(); bool istilehighlighted() const; void turnoffhighlight(); private: sf::rectangleshape m_tile; bool m_ishighlighted; }; tile::tile() { } tile::tile(float squaredim) : m_tile(sf::vector2f(squaredim, squaredim)), m_ishighlighted(false) { } bool tile::istilehighlighted() const { return (m_tile.getoutlinecolor() == sf::color::yellow); } void tile::turnoffhighlight(){ m_tile.setoutlinethickness(0); } void tile::highlighttile() { m_tile.setoutlinethickness(5); m_tile.setoutlinecolor(sf::color::yellow); } tile::~tile(){ } grid::grid(float squaredim) { tile tilepiece(squaredim); sf::vector2f position(0, 0); int counter = 0; //counter whether column or odd int counter1 = 0; //counter whether on or odd row (int row = 0; row < 8; row++) { (int column = 0; column < 8; column++) { if (counter1 % 2 == 0 && counter % 2 == 0 || counter1 % 2 != 0 && counter % 2 != 0) { tilepiece.setfillcolor(sf::color::red); } else { tilepiece.setfillcolor(sf::color::white); } tilepiece.setposition(position); m_tileset[row][column] = tilepiece; //correct coordinates m_gridmap[row][column] = sf::vector2f(tilepiece.getposition().x + squaredim / 2, tilepiece.getposition().y + squaredim / 2); position.x += squaredim; counter++; } position.y += squaredim; position.x = 0; counter = 0; counter1++; } }
the tiles not rendering. i'm not sure issue or whether i'm doing wrong inheritance here , whether should have m_tile , makes sense..
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
you trying draw tile
object (i suppose so, did not show code draws). never set dimensions, that's why can't see it. set dimensions member variable ( m_tile(sf::vector2f(squaredim, squaredim))
) not used if draw tiles this: window.draw(tile)
.
you have choose: either inherit publicly rectangleshape or contain member object rectangleshape, not both.
Comments
Post a Comment