Jump to content
  • Advertisement
Sign in to follow this  
CoffeeSlave

Toggling tiles On/Off problem

This topic is 2477 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
Advertisement
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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!