Hello there! I'm fairly new to Sfml C++,
I have a problem with drawing an vertexarray that's inside a class. This code does work outside the class.
My only output is the phrase: "Tile is created" on the console. Please help!
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
struct Tile64
{
public:
sf::VertexArray quad;
Tile64(float xPos, float yPos, sf::Color color)
{
sf::VertexArray quad(sf::Quads, 4);
// define it as a rectangle, located at (10, 10) and with size 100x100
quad[0].position = sf::Vector2f(xPos, yPos);
quad[1].position = sf::Vector2f(xPos + 64, yPos);
quad[2].position = sf::Vector2f(xPos + 64, yPos + 64);
quad[3].position = sf::Vector2f(xPos, yPos + 64);
quad[0].color = color;
quad[1].color = color;
quad[2].color = color;
quad[3].color = color;
cout << "Tile is created" << endl;
}
};
int main()
{
sf::RenderWindow window(sf::VideoMode(320, 320), "Tilemap");
Tile64 tile(10, 10, sf::Color::Red);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window.close();
}
window.clear();
window.draw(tile.quad);
window.display();
}
return 0;
}
Thank you!