![](/img/trans.png)
[英]What's the difference between getLocalBounds and getGlobalBounds in sfml c++?
[英]getLocalBounds alternative for Text Objects? (SFML)
尝试使用 SFML 为 Comp Sci final 制作按钮,并且真的不想在每个按钮上绘制不可见的精灵。
我找到了一些解决方案,但它们都使用旧版本的 sfml,并且这些功能已被删除或更改,并且不确定它们已更改为什么。
while(window.isOpen()){
Event event;
while(window.pollEvent(event)){
switch(event.type)
{
case Event::Closed:
window.close();
cout << "Window Closed!" << endl;
break;
case Event::MouseButtonPressed:
if(event.mouseButton.button == Mouse::Left){
cout << " if(event.mouseButton.button == Mouse::Left){" << endl;
if(equationsButtonText.getLocalBounds().contains(event.mouseButton.x, event.mouseButton.y)){
cout << "This works!" << endl;
}
}
default:
break;
}
}
}
cout << " if(event.mouseButton.button == Mouse::Left){" << endl; 只是为了测试它进入循环有多远。
getLocalBounds
返回文本本地坐标的边界。 您需要使用getGlobalBounds
在世界坐标中获取它。
您还需要使用窗口的mapPixelToCoords
方法将鼠标的坐标也转换为世界坐标。
它会是这样的:
if(equationsButtonText.getGlobalBounds().contains(window.mapPixelToCoords({event.mouseButton.x, event.mouseButton.y}))){
cout << "This works!" << endl;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.