Jump to content
  • Advertisement
Sign in to follow this  

Toggling tiles On/Off problem

This topic is 2651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I grabbed SFML and started writing my first game yesterday which will be a clone of Lights Out.

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.

bool lit = false;

Tile constructor makes lit = false.

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

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

Am I making a very silly mistake somewhere?

Share this post

Link to post
Share on other sites
bool lit = false;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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!