Sign in to follow this  
CoffeeSlave

Toggling tiles On/Off problem

Recommended Posts

CoffeeSlave    102
I grabbed SFML and started writing my first game yesterday which will be a clone of [url="http://en.wikipedia.org/wiki/Lights_Out_(game)"]Lights Out[/url].

I set up a board full of clickable tiles and tried to make them individually toggle on and off. They all start in the unlit state, but most of them - when clicked for the first time - try and click themselves off again before working normally. I've been banging my head against a wall trying to work out where I've gone wrong, but it's eluding me. I might even be using SFML incorrectly when switching the sprite's image but I'm not sure.

I have a board class which holds the tiles from a tile class.

[code]bool lit = false;[/code]

Tile constructor makes lit = false.

[code]void tile::toggle()
{
if (lit == true) {Sprite.SetImage(mainboard.LightOff); lit = false;}
else {Sprite.SetImage(mainboard.LightOn); lit = true;}
}[/code]

mainboard holds the on/off images. The compiler also complains [i]"warning: unused variable 'lit' "[/i].

Am I making a very silly mistake somewhere?

Share this post


Link to post
Share on other sites
Wooh    1088
[code]bool lit = false;[/code]This creates a local variable that is different from tile::lit. That is why you get the warning.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this