Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - perensoep109

Pages: [1]
1
Graphics / Re: Drawing vertexarray inside a class doesn't work
« on: January 08, 2018, 09:16:49 am »
Well, I thought this would create the variable. And later on in the class. It would give the variable it's data. Because, when I remove the quad from the class. It gives me an error message. I can't reach the quad variable without that quad outside of the constructor.

2
Graphics / Drawing vertexarray inside a class doesn't work
« on: January 07, 2018, 08:31:44 pm »
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!

Pages: [1]
anything