Bienvenue, Invité. Merci de vous connecter ou de vous inscrire.
Avez-vous perdu votre e-mail d'activation ?

Auteur Sujet: [SFML 2.0] Probleme affichage image  (Lu 2285 fois)

0 Membres et 1 Invité sur ce sujet

fische_s

  • Newbie
  • *
  • Messages: 3
    • Voir le profil
[SFML 2.0] Probleme affichage image
« le: Janvier 05, 2013, 05:43:51 pm »
Bonjour,

Je suis actuellement en train de developper un jeux multi-plateforme. J'ai realisé un menu basique.

Sur linux celui-ci fonctionne parfaitement.

Mais en revanche sur windows quand on passe des Options au Menu principal il y a un reaffichage des images contenu dans les Options dans le Menu principal.

Avez vous une idée du probleme.

Pour info je crée une nouvel boucle d'evenement à chaque fois que je rentre dans un sous Menu style Options. (Est-ce la bonne methode?)
Et mes sous Menu sont des foncteur. Et donc j'ai un tableau de pointeur sur foncteur pour les stocker.

Si vous souhaitez plus d'informations n'hesitez pas.

Cordialement,

Fische_s

flow10000

  • Newbie
  • *
  • Messages: 29
    • Voir le profil
    • Project Abyss
Re : [SFML 2.0] Probleme affichage image
« Réponse #1 le: Janvier 06, 2013, 12:02:05 pm »
Salut,
Un peu de code serait le bienvenue

fische_s

  • Newbie
  • *
  • Messages: 3
    • Voir le profil
Re : [SFML 2.0] Probleme affichage image
« Réponse #2 le: Janvier 07, 2013, 09:36:02 am »
Bonjour,

Voici un peu de code.

Ma classe Menu:
#include <SFML/Graphics/RenderStates.hpp>
#include <iostream>
#include <SFML/Window/Mouse.hpp>
#include "Image.hh"
#include "Menu.hh"
#include "ClicExit.hh"
#include "ClicOptions.hh"
#include "ClicParties.hh"
#include "Sound.hh"

Menu::Menu()
{
    window.create(sf::VideoMode(800, 600), "Do you want a R-TYPE ? You'll have soon");
    action[0] = PositionAction(350, 150, new ClicParties);
    action[1] = PositionAction(350, 250, new ClicOptions);
    action[2] = PositionAction(350, 350, new ClicExit);
    nav = new Sound("../utils/sound/Nav.ogg");
    sound = new Sound("../utils/sound/Intro.ogg");
    lSound.push_back(nav);
    lSound.push_back(sound);
}

Menu::~Menu()
{
    lWidget.clear();
    lSound.clear();
    delete nav;
    delete sound;
}

void        Menu::load()
{
    lWidget.push_back(new Image("../utils/pictures/rType.png", sf::Vector2f(150, 0)));
    lWidget.push_back(new Image("../utils/pictures/fondMob.jpg", sf::Vector2f(600, 360)));
    lWidget.push_back(new Bouton("../utils/pictures/BoutonParties.png", sf::Vector2f(350, 150)));
    lWidget.push_back(new Bouton("../utils/pictures/BoutonOptions.png", sf::Vector2f(350, 250)));
    lWidget.push_back(new Bouton("../utils/pictures/BoutonExit.png", sf::Vector2f(350, 350)));
}

void        Menu::displayWidget()
{
    std::list<AWidget*>::iterator it;

    for (it = lWidget.begin();it != lWidget.end();++it)
        (*it)->Draw(window);
}

void            Menu::start()
{
    window.setActive(true);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (sound->getStatus() == sf::Music::Stopped && sound->getPlaying() == true)
                sound->play();
            if (sound->getStatus() == sf::Music::Playing && sound->getPlaying() == false)
                sound->stop();
            if (event.type == sf::Event::Closed)
                window.close();

            if (event.type == event.MouseButtonPressed)
                for (int i = 0;i < 3;++i)
                {
                    if ((sf::Mouse::getPosition(window).x >= action[i].x1 && sf::Mouse::getPosition(window).x <= action[i].x2)
                            && (sf::Mouse::getPosition(window).y >= action[i].y1 && sf::Mouse::getPosition(window).y <= action[i].y2))
                    {
                        if (nav->getPlaying() == true)
                            nav->play();
                        (*this->action[i].func)(window, lSound);
                    }
                }
            displayWidget();
            window.display();
        }
    }
}
 

Ma classe Options:

#include <iostream>
#include <SFML/Graphics/Font.hpp>
#include "ClicOptions.hh"
#include "Bouton.hh"
#include "BoutonSwitch.hh"

ClicOptions::ClicOptions()
{
    loaded = false;
}

ClicOptions::~ClicOptions()
{
}

void    ClicOptions::load()
{
    lWidget.push_back(new Bouton("../utils/pictures/BoutonOptions.png", sf::Vector2f(350, 50)));
    lWidget.push_back(new Bouton("../utils/pictures/BoutonMenu.png", sf::Vector2f(150, 50)));
    b = new BoutonSwitch("../utils/pictures/BoutonSOn.png", "../utils/pictures/BoutonSOff.png", sf::Vector2f(350, 200));
    lWidget.push_back(b);
    lWidget.push_back(new Bouton("../utils/pictures/ImgMoins.png", sf::Vector2f(100, 300)));
    lWidget.push_back(new Bouton("../utils/pictures/ImgPlus.png", sf::Vector2f(650, 300)));
    for (int i = 0;i < 10;++i)
        lVol.push_back(new Bouton("../utils/pictures/ImgVol.png", sf::Vector2f((i * 50) + 150, 300)));
    loaded = true;
}

void    ClicOptions::displayWidget(sf::RenderWindow &window)
{
    std::list<AWidget*>::iterator it;
    std::list<Bouton*>::iterator itt;

    for (it = lWidget.begin();it != lWidget.end();++it)
            (*it)->Draw(window);
    for (itt = lVol.begin();itt != lVol.end();++itt)
            (*itt)->Draw(window);
}

void    ClicOptions::changeSound(sf::Event &event, sf::RenderWindow &window, std::list<Sound*> &lSound)
{
    if (event.type == event.MouseButtonPressed &&
            (sf::Mouse::getPosition(window).x >= 350 && sf::Mouse::getPosition(window).y <= 350 +80) &&
            (sf::Mouse::getPosition(window).y >= 200 && sf::Mouse::getPosition(window).y <= 200 + 30))
        b->switchImage(lSound);
}

void    ClicOptions::changeVolume(sf::Event &event, sf::RenderWindow &window, std::list<Sound*> &lSound)
{
    std::list<Bouton*>::reverse_iterator it;
    std::list<Bouton*>::iterator itt;
    if (event.type == event.MouseButtonPressed &&
            (sf::Mouse::getPosition(window).x >= 100 && sf::Mouse::getPosition(window).x <= 100 + 40) &&
            (sf::Mouse::getPosition(window).y >= 300 && sf::Mouse::getPosition(window).y <= 300 + 40))
    {
        int i = 0;
        for (it = lVol.rbegin();it != lVol.rend() && i == 0;++it)
        {
            if ((*it)->isUse() == true)
            {
                (*it)->changeUse();
                i = 1;
            }
        }
    }
    if (event.type == event.MouseButtonPressed &&
            (sf::Mouse::getPosition(window).x >= 650 && sf::Mouse::getPosition(window).x <= 650 + 40) &&
            (sf::Mouse::getPosition(window).y >= 300 && sf::Mouse::getPosition(window).y <= 300 + 40))
    {
        int i = 0;
        for (itt = lVol.begin();itt != lVol.end() && i == 0;++itt)
        {
            if ((*itt)->isUse() == false)
            {
                (*itt)->changeUse();
                i = 1;
            }
        }

    }
    std::list<Sound*>::iterator ite;
    float vol = 0;
    for (itt = lVol.begin();itt != lVol.end();++itt)
    {
        if ((*itt)->isUse() == true)
            vol += 1.0;
    }
    vol *= 10.0;
    for (ite = lSound.begin();ite != lSound.end();++ite)
        (*ite)->volume(vol);
}

void    ClicOptions::operator ()(sf::RenderWindow &window, std::list<Sound*> &lSound)
{
    sf::Font f;
    f.loadFromFile("../utils/police/Alien-Encounters.ttf");
    sf::Text *bText = new sf::Text("Sound :", f);
    bText->setPosition(150, 200);
    sf::Text *bT = new sf::Text("Volume", f);
    bT->setPosition(300, 250);
    if (loaded == false)
        load();

    int i = 1;
    while (window.isOpen() && i != 0)
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == event.MouseButtonPressed &&
                    (sf::Mouse::getPosition(window).x >= 150 && sf::Mouse::getPosition(window).x <= 150 + 80) &&
                    (sf::Mouse::getPosition(window).y >= 50 && sf::Mouse::getPosition(window).y <= 50 + 30))
                i = 0;
            changeSound(event, window, lSound);
            changeVolume(event, window, lSound);
        }
        window.clear();
        window.draw(*bText);
        window.draw(*bT);
        displayWidget(window);
        window.display();
        if (i == 0)
            window.clear();
    }
}
 

fische_s

  • Newbie
  • *
  • Messages: 3
    • Voir le profil
Re : [SFML 2.0] Probleme affichage image
« Réponse #3 le: Janvier 09, 2013, 09:42:04 pm »
Une petite reponse !?  :) :) :)

 

anything