How to Lock Window Resize C++ sfml?
Last Updated :
02 Jan, 2023
Multimedia components in computers can be easily interfaced using SFML (Simple and Fast Multimedia Library), a cross-platform library for software development. The software runs on Windows, Linux, Mac OS X, iOS, and Android operating systems. Video games and graphical programs can be developed quickly and easily with SFML’s set of tools. Among its features are graphics, audio, networking, and system functions. In addition, it provides classes for managing windows and for capturing user input.
In order to prevent a window from being resized in SFML, you can use the sf::Window::setSize method to set the window’s size to a fixed value.
Before using sf::Window::setSize:
Example:
C++
#include <SFML/Window.hpp>
#include <iostream>
int main()
{
sf::Window window(sf::VideoMode(600, 600), "SFML WORK!" );
window.setSize(sf::Vector2u(600, 600));
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
window.clear();
window.display();
}
return 0;
}
|
Output:
Explanation: In this example, we create a window with a size of 600 x 600 pixels, and then use the setSize method to set the window’s size to the same value. This effectively prevents the user from resizing the window.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...