I come from python/pygame where the methods are made for you. However looking through sfml, i dont see such methods as in pygame. such as rect.collidepoint() for mouse or rect.colliderect() for collision test against another rect. Do you have to make these yourself in sfml?
If so i am not quite sure on how to make these functions.
I set up the base classes, i am just not sure on how to check if the mouse is inside the rect or not?
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
class Rect{
public:
sf::RectangleShape rect;
Rect(){
rect.setSize(sf::Vector2f(100,100));
rect.setPosition(sf::Vector2f(10,10));
rect.setFillColor(sf::Color::Red);
}
};
class Control{
public:
sf::RenderWindow window;
Rect obj;
Control(){
window.create(sf::VideoMode(600,400), "Title");
window.setKeyRepeatEnabled(false);
}
void update(sf::Event event){
window.clear(sf::Color::Black);
window.draw(obj.rect);
window.display();
}
void event_handler(sf::Event event){
while(window.pollEvent(event)){
if (event.type == sf::Event::Closed){
window.close();
}
}
}
void run(){
while (window.isOpen()){
sf::Event event;
event_handler(event);
update(event);
}
}
};
int main(){
Control app;
app.run();
}