Bienvenue, Invité. Merci de vous connecter ou de vous inscrire. Avez-vous oublié d'activer ?

Messages récents

Pages: « Précédente 1 [2] 3 4 ... 10 Suivante »
11
Graphique / Re: getGlobalBounds : coin supérieur gauche ?
« Dernier message par christophedlr le Décembre 16, 2024, 08:33:18 pm »
Merci pour ta réponse, je teste ça samedi quand je vais me remettre dessus (j'ai un boulot toute la semaine, je bosse le jeu que le samedi du coup ^^), et je te dis ce qu'il en est ensuite.
12
Graphique / Re: getGlobalBounds : coin supérieur gauche ?
« Dernier message par G. le Décembre 15, 2024, 01:17:00 am »
T'as 2 transformable, ta Station (puisqu'elle hérite de Transformable) et ta donnée membre m_station (qui est un CircleShape qui hérite aussi de Transformable).
Quand tu fais tes m_stations[0].setPosition(...) ils s'appliquent à ton transformable Station, mais pas à sa donnée membre m_station qui reste à sa position d'origine 0, 0. Ton m_station s'affiche correctement au bon endroit car tu récupères la transformation de Station avec ton getTransform() dans ta fonction draw.

Pour que ton Station::getGlobalBounds() renvoie ce que tu veux il faut donc aussi appliquer la transformation de Station à ton m_station avant de renvoyer ce rectangle, et si je me souviens bien ça donnerait :
getTransform().transformRect(m_station.getGlobalBounds());

Ensuite ça reste une détection de clic dans un rectangle/carré donc pas forcément idéal pour un Cercle mais ça c'est à toi de voir :p (les calculs pour voir si un point est dans un cercle sont très facile)
13
Graphique / [Résolu] getGlobalBounds : coin supérieur gauche ?
« Dernier message par christophedlr le Décembre 14, 2024, 12:12:05 pm »
Bonjouur,

Je tombe présentement sur un nouveau problème dans mon projet : j'ai deux sf::CircleShape dans ma fenêtre, chacune représentant des stations de trains. Je voudrais détecter que je clique gauche sur une des stationis.

Mon problème est le suivant : j'instancie ma station qui est un sf::Drawable et sf::Transformable, je lui donne une position aléatoire dans ma fenêtre. Jusque là tout va bien, mais quand je récupère le getGlobalBounds, les coordonnées left & top sont le coin supérieur-gauche de la fenêtre.

Après plusieurs tests, je me suis aperçus que si je retire la ligne :
states.transform *= getTransform();

de ma méthode draw, mon setPosition ne fonctionne plus puisque la transformation n'est plus appliquée, ce qui m'obligerai à créer la méthode setPosition et l'appliquer à mon sf::CircleShape (ce que je n'ai pas fait.

Bref, donc mon setPosition n'est pas appliqué et ma statioon se retrouve donc... dans le coin supérieur-gauche de l'écran.

Ce qui veut dire que getGlobalBounds me renvoi non pas les coordonnées après transformation (ici un setPosition), mais avant. Pourtant la documentation SFML 2.6 dit que c'est lel getLocalBounds qui ignore les transformations.

Je précise : je n'ai paas testé d'appeler le getLocalBounds pour voir si j'avais une inversion des deux, mais j'ai en tout cas un comportement avec le getGloballBounds, différent de ce que m'indique la documentation.


Je vous laisse le code de mes deux classes.

Station.cpp :
#include "Station.h"

Station::Station()
{
    m_station.setFillColor(convertHexaToColor("fae20a"));
    m_station.setOutlineColor(convertHexaToColor("c5c5c5"));

    m_station.setRadius(10);
    m_station.setOutlineThickness(3);

    m_station.setOrigin(m_station.getRadius(), m_station.getRadius());
}

Station::~Station()
{
    //dtor
}

sf::FloatRect Station::getGlobalBounds() const
{
    return m_station.getGlobalBounds();
}


void Station::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    states.transform *= getTransform();

    target.draw(m_station, states);
}
 

Et Game.cpp qui est la classe qui gère le jeu :
#include <iostream>
#include "Game.h"

Game::Game(Window *window)
{
    sf::Vector2u windowSize = window->getWindow()->getSize();
    m_stations.push_back(Station());
    m_stations.push_back(Station());

    m_ground.setFillColor(sf::Color(255, 255, 255));
    m_ground.setSize(sf::Vector2f(windowSize.x, windowSize.y));
    m_ground.setPosition(0, 0);

    m_stations[0].setPosition(rngInt(20, windowSize.x-20), rngInt(20, windowSize.y-20));
    m_stations[1].setPosition(rngInt(20, windowSize.x-20), rngInt(20, windowSize.y-20));

    window->loop([this](RenderWindow& win) { this->loop(win); });
}

Game::~Game()
{
    //dtor
}

void Game::loop(RenderWindow& window)
{
    sf::Event event;

    window.setRunningLoop(true);

    while (window.pollEvent(event))
    {
        // Close window : exit
        if (event.type == sf::Event::Closed)
            window.close();

        if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
        {
            sf::Vector2f mousePos = window.mapPixelToCoords(sf::Mouse::getPosition(window));

            std::cout << "Station bounds: Left=" << m_stations[0].getGlobalBounds().left << ", Top=" << m_stations[0].getGlobalBounds().top << ", Width=" << m_stations[0].getGlobalBounds().width << ", Height=" << m_stations[0].getGlobalBounds().height << std::endl << std::endl;

            std::cout << "Station 0 position, x=" << m_stations[0].getPosition().x << ", y=" << m_stations[0].getPosition().y << std::endl;
            std::cout << "Mouse position, x=" << mousePos.x << ", y=" << mousePos.y << std::endl;
            std::cout  << m_stations[0].getGlobalBounds().contains(sf::Mouse::getPosition(window).x,  sf::Mouse::getPosition(window).y) << std::endl << std::endl;

            if  (m_stations[0].getGlobalBounds().contains(mousePos))
            {
                std::cout <<  "Cliked station 0";
            }

            /*for (int i=0; m_stations.size(); i++)
            {
                if (m_stations[i].getGlobalBounds().contains(window.mapPixelToCoords(sf::Mouse::getPosition(window))))
                {
                    std::cout << "Station " << i << " left cliked" << std::endl;

                    break;
                }
            }*/

        }
    }

    window.clear();

    window.draw(m_ground);

    window.draw(m_stations[0]);
    window.draw(m_stations[1]);

    window.display();
}
 

Je précise que les coordonnées de la station obtenus avec getPosition sont bons, mais la méthode contains est utilisable sur un sf::FloatRect, donc getGlobalBounds ou getLocalBounds, du coup il ne détecte jamais mon clique SAUF dans le coin supérieur-gauche de l'écran, soit donc la position originelle avant mon setPosition de mon constructeur.


J'ai essayé de voir si ChatGPT pouvait m'aider, mais non, tout ce qu'il me dit ne fonctionne pas. D'après lui, c'est parce que je fais ma vérification avant l'application de la transformation, ce qui est logique vu qu'on gère les événements avant de réappliquer l'affichage. Mais d'un autre côté avant de pouvoir faiire mon clic, il a déjà affiché, donc déjà appliqué le setPosition du constructeur.

Et oui je sais ce que certains vont me dire : "T'embête pas, gère ta position aléatoire directement dans le constructeur de ton Station", oui j'y ai pensé, mais on doit pouvoir aussi changer la position à d'autres moments au besoin ; pas forcément ici pour les stations, mais d'autres éléments pourraient avoir ce besoin, donc j'aimerais comprendre pourquoi ces coordonnées totalement loufoque plutôt que les véritables coordonnées.

Merci d'avance à ceux qui pourront m'aider.
14
Général / Re: Barre de vie mal placé ?
« Dernier message par KathleenFSpillane le Novembre 20, 2024, 08:17:02 am »
The demo code has been adjusted to properly align the health bar, and use more proportional sizes, improving the look and feel of the UI.
15
Discussions générales / Re: MODE 7 LIKE SNES EN SFML
« Dernier message par SylviaSosa le Novembre 16, 2024, 09:41:19 am »
Il semble que cela fait si longtemps que la vidéo n'est plus visible ici, puis-je regarder cette vidéo en apk mod 2024
16
Discussions générales / Re: Je débute avec sfml et j'ai besoin d'aaide
« Dernier message par 23winla2 le Novembre 16, 2024, 03:53:57 am »
Khám Phá 23win: Trải Nghiệm Casino Trực Tuyến Đỉnh Cao
Trong thế giới cá cược trực tuyến, 23win đã nổi bật như một trong những nhà cái hàng đầu, đặc biệt là trong lĩnh vực casino trực tuyến. Với một loạt các trò chơi hấp dẫn và dịch vụ chuyên nghiệp, 23win không chỉ mang đến cho người chơi những trải nghiệm giải trí tuyệt vời mà còn giúp họ tận hưởng cảm giác hồi hộp và kịch tính mà casino mang lại.
https://www.facebook.com/23winla/
https://www.youtube.com/@23winla
https://x.com/23winla
https://www.pinterest.com/23winla/
https://gravatar.com/23winla
https://www.reddit.com/user/23winla/
Đa Dạng Các Trò Chơi Casino
23win cung cấp một bộ sưu tập đa dạng các trò chơi casino, từ những trò chơi bài cổ điển như Baccarat, Poker, và Blackjack, cho đến những máy slot hiện đại với nhiều chủ đề hấp dẫn. Mỗi trò chơi đều được thiết kế với đồ họa sắc nét và âm thanh sống động, tạo ra một bầu không khí chân thật như đang ở trong một casino thực sự.
Điểm nổi bật tại 23win là dịch vụ live casino. Người chơi có thể tham gia vào các bàn chơi trực tiếp với các dealer chuyên nghiệp qua video streaming. Tính năng này không chỉ mang lại cho người chơi cảm giác hồi hộp mà còn cho phép họ tương tác với dealer và các cược thủ khác, tạo ra một trải nghiệm xã hội độc đáo. Khi ngồi tại bàn live casino, người chơi có thể cảm nhận được không khí của một sòng bạc thực thụ ngay tại nhà mình.
Trải Nghiệm Thú Vị Với Các Trò Chơi Slot
Ngoài các trò chơi bài, 23win còn nổi bật với những trò chơi slot phong phú. Các trò chơi slot tại đây có nhiều chủ đề khác nhau, từ cổ điển đến hiện đại, và thường xuyên có các tính năng đặc biệt như vòng quay miễn phí, biểu tượng hoang dã và jackpot. Điều này không chỉ giúp người chơi dễ dàng tìm thấy trò chơi yêu thích mà còn tạo ra cơ hội giành chiến thắng lớn.
Hơn nữa, 23win thường xuyên cập nhật các trò chơi mới nhất từ những nhà phát triển hàng đầu, đảm bảo rằng người chơi luôn có được trải nghiệm mới mẻ và thú vị. Những trò chơi này không chỉ mang lại niềm vui mà còn là một cơ hội tuyệt vời để thử vận may và chiến thuật của bản thân.
Chương Trình Khuyến Mãi Hấp Dẫn
Một trong những yếu tố quan trọng khiến 23win trở thành lựa chọn hàng đầu cho người chơi casino là chính sách khuyến mãi hấp dẫn. Nhà cái thường xuyên triển khai các chương trình thưởng cho người chơi mới, từ tiền thưởng chào mừng đến các ưu đãi đặc biệt cho người chơi lâu năm. Những khuyến mãi này không chỉ giúp người chơi có thêm vốn để tham gia mà còn tạo ra động lực để họ khám phá thêm nhiều trò chơi khác.
Chương trình khuyến mãi bao gồm các phần thưởng cho lần gửi tiền đầu tiên, hoàn tiền cho cược thua và nhiều sự kiện đặc biệt trong tháng. Điều này không chỉ giúp người chơi tăng cường trải nghiệm mà còn khuyến khích họ tiếp tục tham gia.
Dịch Vụ Hỗ Trợ Khách Hàng Chuyên Nghiệp
Để đảm bảo rằng người chơi luôn có trải nghiệm tốt nhất, 23win cung cấp dịch vụ hỗ trợ khách hàng tận tâm và chuyên nghiệp. Đội ngũ hỗ trợ khách hàng tận tâm của chúng tôi luôn sẵn sàng đồng hành cùng bạn mọi lúc, mọi nơi, giúp bạn giải quyết mọi thắc mắc một cách nhanh chóng và chuyên nghiệp.
Dịch vụ hỗ trợ khách hàng không chỉ giúp người chơi giải quyết nhanh chóng các vấn đề mà còn tạo ra sự yên tâm khi tham gia cá cược. Sự chuyên nghiệp và thái độ thân thiện của đội ngũ hỗ trợ là một trong những yếu tố quan trọng giúp 23win xây dựng được lòng tin từ phía người chơi.
Kết Luận: Tại Sao Nên Chọn 23win Để Chơi Casino?
Tóm lại, 23win không chỉ là một nhà cái trực tuyến mà còn là một điểm đến lý tưởng cho những ai đam mê casino và các trò chơi giải trí hấp dẫn. Với sự đa dạng trong dịch vụ, giao diện thân thiện và nhiều khuyến mãi hấp dẫn, 23win xứng đáng là lựa chọn hàng đầu cho những ai đang tìm kiếm một trải nghiệm casino trực tuyến tuyệt vời. Nếu bạn đang tìm kiếm một nơi để thử sức và khám phá những điều mới mẻ trong thế giới casino, hãy đến với 23win để trải nghiệm những giây phút giải trí đỉnh cao mà nhà cái này mang lại.
Website: https://23win.la/
17
Python / Comment créer une application jolie et utilisable en utilisant Dear Imgui ?
« Dernier message par aaroncarter le Novembre 12, 2024, 05:20:27 am »
Salut les gars. Ma question ne concerne pas spécifiquement SFML mais plutôt Dear Imgui utilisant SFML comme backend. Je souhaite créer une application utilisable pour la gestion des chats errants qu'une ONG souhaite. J'aimerais donc la rendre jolie et utilisable. J'aimerais savoir s'il existe des exemples, des démos ou des sources pour apprendre à rendre votre application plus jolie et plus professionnelle.

Je suis désolé si la question n'est pas bonne pour ce sous-titre. J'accepte également les suggestions d'autres sous-titres plus alignés sur cette question. slope game
18
Graphique / Re: Texture.update() ne donne pas le résultat attendu
« Dernier message par AllenCalderon le Octobre 03, 2024, 07:32:45 am »
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).
19
Général / C:\...\project.exe le fichier spécifié est introuvable
« Dernier message par gwilili le Septembre 30, 2024, 09:59:42 am »
Bonjour, j'ai besoin d'aide pour faire fonctionner un programme, le fichier executable semble absent. J'ai déjà re-générer et alterner les modes débog et release sans succès. Cela me bloquepour tester la totalité de mes programmes. à l'aide !!
20
Discussions générales / Re: Je débute avec sfml et j'ai besoin d'aaide
« Dernier message par EugeneHogan le Septembre 29, 2024, 05:42:49 pm »
Bonjour !
Je ne sais pas si vous avez déjà résolu ce problème ? Voici ma suggestion
Il semble que vous ayez deux problèmes distincts dans votre projet SFML sous Visual Studio 2022 :
- Avertissement sur Glyph : Ce message indique que certaines variables membres de la classe Glyph ne sont pas initialisées. Cela peut être un avertissement lié au code SFML, mais ne devrait pas empêcher la compilation. Vous pouvez l'ignorer pour l'instant, sauf si cela entraîne des comportements indésirables.
- Erreur de lien WinMain : Cela signifie que votre projet n'est pas configuré pour être une application Windows. Assurez-vous que vous avez bien configuré votre projet en tant qu'application console (ou application Windows si vous utilisez main comme point d'entrée). Pour cela :
- Allez dans les propriétés du projet. banana game
Sous "Configuration Properties" > "Linker" > "System", vérifiez que le "SubSystem" est défini sur "Console" ou "Windows" selon votre besoin.
Après ces ajustements, essayez de reconstruire votre projet. Si vous avez d'autres questions, n'hésitez pas !
Pages: « Précédente 1 [2] 3 4 ... 10 Suivante »