1
General / Re: Modify textures stored in vector
« on: June 25, 2018, 04:14:10 pm »
I finally made it work with this:
I shoud just have initialized the vector like this:
and not like this:
even if I don't really know why ^^
Thank you!
Code: [Select]
#include <vector>
#include "Test.h"
int main()
{
sf::VideoMode DesktopMode = sf::VideoMode::getDesktopMode();
sf::RenderWindow window;
window.create(DesktopMode,"The Game", sf::Style::Fullscreen);
Test fleetButton(sf::Vector2f(500,500),"TextA");
std::vector<Test*> listOfButtons;
listOfButtons.push_back(&fleetButton);
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// on regarde le type de l'évènement...
switch (event.type)
{
// fenêtre fermée
case sf::Event::Closed:
window.close();
break;
// touche pressée
case sf::Event::KeyPressed:
return 0;
break;
// on ne traite pas les autres types d'évènements
default:
break;
}
if (event.type == sf::Event::MouseButtonPressed)
{
if (event.mouseButton.button == sf::Mouse::Left)
{
listOfButtons[0]->setText("Heyy");
}
}
}
window.clear(sf::Color::Black);
window.draw(*listOfButtons[0]->getSprite());
window.draw(*listOfButtons[0]->getText());
window.display();
}
}
I shoud just have initialized the vector like this:
Code: [Select]
std::vector<Test*> listOfButtons;
and not like this:
Code: [Select]
std::vector<Test> listOfButtons;
even if I don't really know why ^^
Thank you!