Class constructor problem

Hello can anyone tell me what's wrong here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <cstdio>

class Button
{
        public:
	bool visible;
	sf::Texture texture, keimenotexture;
	sf::Sprite sprite, keimeno;
	
	Button(std::string filepath, int x, int y, bool shown=true)
	{
		visible = shown;
		texture.loadFromFile(filepath);
		sprite.setTexture(texture);
		sprite.setPosition(x,y);
	}
	Button(std::string filepath, std::string keimenopath, int x, int y, int kx, int ky, bool shown)
	{
		visible = shown;
		texture.loadFromFile(filepath);	
		sprite.setTexture(texture);
		sprite.setPosition(x,y);
		keimenotexture.loadFromFile(keimenopath);
		keimeno.setTexture(keimenotexture);
		keimeno.setPosition(kx,ky);
	}		
	bool isvisible() {return visible;}
	void display(sf::RenderWindow *window) {if (visible) window->draw(sprite);}
	void keimenodisplay(sf::RenderWindow *window) {window->draw(keimeno);}		
};




int main()
{
	using namespace sf;
	Button exitbutton("resources/o1.png","resources/keimeno1.png",0,0,100,100,true);	
	RenderWindow window(VideoMode(640,480),"Button test",Style::Default);
	
	while (window.isOpen())
	{
		Event event;
		while (window.pollEvent(event))
		{
			if (event.type == Event::Closed)
                window.close();
		}
		
			
		window.clear(Color::White);
		exitbutton.display(&window);
		exitbutton.keimenodisplay(&window);
		printf("%i",(int)exitbutton.isvisible());
		window.display();
	}
}


SFML is a graphics library. In my program it works properly. My problem is that when i construct Button exitbutton, with bool shown = true, it constructs it with exitbutton.visible = false. Printf prints 0 all the time and exitbutton.display() does nothing because visible = false. In the constructor though, i have the line visible=shown. What's wrong?
Last edited on
printf is displaying 1 for me. Everything in my code should be same as yours except it isn't loading the textures. ...try rebuilding? It's the only thing I can think of sorry.
Last edited on
Topic archived. No new replies allowed.