Hello!
I'm working on a basic platformer, trying to get used to using C++ instead of Python, and I was going to make a tile-based system.
I had no problem creating a two-dimensional array of Sprites and drawing those onto the screen. It's when I started to try and create a "Tile" class to have a bit more functionality that I started running into problems.
My C++ is pretty rusty, but I think that I'm doing everything right in terms of C++ syntax. I want to create my "Tile" class and make it extend Sprite. I assumed that I should be able to simply call renderwindow.Draw(someTile) and that it would correctly draw things.
Here is my tile class:
#ifndef TILE_H_INCLUDED
#define TILE_H_INCLUDED
#include <SFML/Graphics.hpp>
class Tile : public sf::Sprite{
public:
Tile() : sf::Sprite(), solid(false){};
Tile(sf::Image img, sf::Vector2f pos, bool sol) : sf::Sprite(img, pos), solid(sol){};
bool solid;
};
#endif // TILE_H_INCLUDED
However, every time I try to draw a tile, it draws the correct size (in this case the image is 32x32) but all of the pixels are always white!
I'm creating my tile object like this:
Tile test(tileset[1], sf::Vector2f(0,0), true);
And drawing it like this:
window.Draw(test);
tileset is an array of Images, this seems to be working correctly, because if I just create a Sprite from tileset[1] it displays correctly.
Am I doing something wrong? Should I just include a Sprite in my Tile class, instead of extending the Sprite class?
Thanks!
-Sam