I'm trying to recreate another pong game. Why you might ask, well because as i learn C++ i'm learning better design, etc. I don't practice C++ regularly but more like once every 2 weeks because of school and work! So i would like some help and perhaps no hard comments. I've managed to make it work before but can't seem to remember! So this is what i'm doing:
1) created a class named Entities that contains a constructor with specific parameters properties for sf::RectangleShape, sf::Circle, etc.
2) I then created 4 variables of data type sf::RectangleShape, sf::Circle, etc. as private member variables.
3) i created 4 getFunctions that will return the variables.
Entities.h
#include <SFML/Graphics.hpp>
#include "ResourcePath.hpp"
class Entities
{
public:
sf::RectangleShape rect;
sf::CircleShape circle;
sf::Text text;
sf::Font font;
public:
Entities();
Entities(sf::Vector2f size, sf::Vector2f position, sf::Color color);
Entities(int radius, sf::Vector2f position, sf::Color color);
Entities(std::string message, int charSize, sf::Vector2f position, sf::Font font, sf::Color color);
sf::RectangleShape getRectangle();
sf::CircleShape getCircle();
sf::Text getText();
sf::Font getFont();
};
#endif /* defined(__PongClone__entities__) */
Entities.cpp
#include "entities.h"
Entities::Entities()
{
font.loadFromFile(resourcePath() + "");
}
Entities::Entities(sf::Vector2f size, sf::Vector2f position, sf::Color color)
{
rect.setSize(size);
rect.setPosition(position);
rect.setFillColor(color);
}
Entities::Entities(int radius, sf::Vector2f position, sf::Color color)
{
circle.setRadius(radius);
circle.setPosition(position);
circle.setFillColor(color);
}
Entities::Entities(std::string message, int charSize, sf::Vector2f position, sf::Font font, sf::Color color)
{
text.setString(message);
text.setCharacterSize(charSize);
text.setPosition(position);
text.setFont(font);
text.setColor(color);
}
sf::RectangleShape Entities::getRectangle()
{
return rect;
}
sf::CircleShape Entities::getCircle()
{
return circle;
}
sf::Text Entities::getText()
{
return text;
}
sf::Font Entities::getFont()
{
return font;
}
Now i have another class which will create specific objects. For example, i created a leftpaddle object like this:
Entities leftPaddle(Entities(sf::Vector2f(100,100), sf::Vector2f(200,200), sf::Color::White));
I've got all that working but when i try to draw the object i get and error like this:
"invalid use of non-static data member 'rect'"
ive tried
window->draw(getRectangle().leftPaddle);
but none of it works, also sorry for the wrong programming lingo!
Thanks for anyone willing to help and for your time spent!