also here is the code that derived the earlier code
#include <SFML/Graphics.hpp>
#include <vector>
#define ONE
#define TWO
#define THREE
#define POSX 300
#define POSY 200
std::vector<sf::Sprite> bSprite(3);
void add(sf::Image, int);
int check(sf::RenderWindow*);
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Test for the button etc");
sf::Image One;
sf::Image Two;
sf::Image Three;
if(!One.LoadFromFile(ONE))
return EXIT_FAILURE;
if(!Two.LoadFromFile(TWO))
return EXIT_FAILURE;
if(!Three.LoadFromFile(THREE));
return EXIT_FAILURE;
add(One, 0);
add(Two, 1);
add(Three, 2);
bSprite[0].SetPosition(POSX, POSY);
bSprite[1].SetPosition(POSX, POSY);
bSprite[2].SetPosition(POSX, POSY);
while(App.IsOpened())
{
sf::Event ev1;
while(App.GetEvent(ev1))
if(ev1.Type == sf::Event::Closed)
App.Close();
int x;
App.Clear();
x = check(&App);
if( !x == 1)
App.Draw(bSprite[0]);
App.Display();
}
return EXIT_SUCCESS;
}
void add(sf::Image b, int i)
{
bSprite[i].SetImage(b);
}
int check(sf::RenderWindow * g)
{
while(g->GetInput().GetMouseX >
bSprite[1].GetPosition().x &&
g->GetInput().GetMouseX <
bSprite[1].GetPosition.x + 100 &&
g->GetInput().GetMouseY >
bSprite[1].GetPosition().y &&
g->GetInput().GetMouseY <
bSprite[1].GetPosition().y + 30 &&
g->GetInput().IsMouseButtonDown() == true )
{
g->Draw(bSprite[2]);
return 1;
}
while(g->GetInput().GetMouseX > bSprite[1].GetPosition().x && g->GetInput().GetMouseX < bSprite[1].GetPosition.x + 100 && g->GetInput().GetMouseY > bSprite[1].GetPosition().y && g->GetInput().GetMouseY < bSprite[1].GetPosition().y + 30 )
{
g->Draw(bSprite[1]);
return 1;
}
return 0;
}
only problem here is that the check function doesn't work because the sprites...
I'm guessing it's because they fail to load(this doesn't compile at all)