@binary1248
In the past 3 years of programming , i have never used a debugger. I have always used print statements to determine a value. I attempted to figure out how to use the debugger in Geany IDE, but i couldnt figure the process out.
@windertime
are you referring to:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
int main(){
sf::RenderWindow window(sf::VideoMode(600,400), "Title", sf::Style::Titlebar | sf::Style::Close);
sf::Vector2f position;
sf::RectangleShape rect;
float width, height;
rect.setFillColor(sf::Color(200,200,200));
width = 100.0;
height = 20.0;
position = {100.0,100.0};
rect.setSize(sf::Vector2f(width, height));
rect.setPosition(position);
sf::Vector2i mouse;
while (window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();
else if(event.type == sf::Event::MouseMoved){
int mousex = event.mouseMove.x;
int mousey = event.mouseMove.y;
if (mousex > position.x &&
mousex < (position.x + width) &&
mousey > position.y &&
mousey < position.y + height){
rect.setFillColor(sf::Color(50,50,50));
}
else{
rect.setFillColor(sf::Color(200,200,200));
}
}
}
window.clear(sf::Color::Black);
window.draw(rect);
window.display();
}
}
because i still get the same problem.
And regarding mapPixelToCoors. What does this even do? Yes i read the docs. but "Convert a point from target coordinates to world coordinates. " doesn't make sense to me. Trying to read the SFML documentation in the eyes of a newbie is like trying to learn Greek.
This function finds the pixel of the render-target that matches the given 2D point. In other words, it goes through the same process as the graphics card, to compute the final position of a rendered point.
Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render-target, this assertion is not true anymore, ie. a point located at (150, 75) in your 2D world may map to the pixel (10, 50) of your render-target – if the view is translated by (140, 25).
This version uses a custom view for calculations, see the other overload of the function if you want to use the current view of the render-target.
I dont know if this is just me or not, but i read this over like 10 times and still i am like WTF?
EDIT:
ok i think you mean this?
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
int main(){
sf::RenderWindow window(sf::VideoMode(600,400), "Title", sf::Style::Titlebar | sf::Style::Close);
sf::Vector2f mouse;
sf::Vector2f position;
sf::RectangleShape rect;
float width, height;
rect.setFillColor(sf::Color(200,200,200));
width = 100.0;
height = 20.0;
position = {100.0,100.0};
rect.setSize(sf::Vector2f(width, height));
rect.setPosition(position);
while (window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();
else if(event.type == sf::Event::MouseMoved){
mouse = window.mapPixelToCoords(sf::Vector2i(event.mouseMove.x,event.mouseMove.y));
}
if (mouse.x > position.x &&
mouse.x < (position.x + width) &&
mouse.y > position.y &&
mouse.y < position.y + height){
rect.setFillColor(sf::Color(50,50,50));
}
else{
rect.setFillColor(sf::Color(200,200,200));
}
}
window.clear(sf::Color::Black);
window.draw(rect);
window.display();
}
}
if so even after using mappixeltocoords, i stll have the same problem.