Veuillez essayer d'exécuter ce code: geometry dash meltdown#include <SFML/Graphics.hpp>
sf::Image fill_shape(int x, int y, sf::Image img){
sf::Image new_image = img;
sf::Color BLUE = sf::Color::Blue; // Define BLUE
new_image.setPixel(x, y, BLUE); // Set the pixel color
return new_image;
}
int main()
{
// Load an image file from a file
sf::Texture texture;
if (!texture.loadFromFile("image.jpg")){
return EXIT_FAILURE;
}
sf::Sprite sprite(texture);
// Get window dimensions based on texture size
int windowWidth = sprite.getTexture()->getSize().x * sprite.getScale().x;
int windowHeight = sprite.getTexture()->getSize().y * sprite.getScale().y;
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "Image Filler");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed){
window.close();
}
else if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
// Get mouse position relative to the window
sf::Vector2i position = sf::Mouse::getPosition(window);
int x = position.x;
int y = position.y;
// Copy image from texture
sf::Image image = sprite.getTexture()->copyToImage();
sf::Image new_image = fill_shape(x, y, image);
// Update the texture with the modified image
texture.update(new_image);
// No need to call sprite.setTexture again since it is already using texture
}
}
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}
Changements clés :- Utilisation de sf::Mouse::getPosition(window) pour obtenir la position de la souris relative à la fenêtre.
- Correction de la couleur BLEU avec sf::Color::Blue.
- Mise à jour correcte de la texture avec texture.update(nouvelle_image).