Problem With Updating Image With Bools

Hello everyone.

This is my problem: I have a bool on the class level named “isOn”. If the player walks onto a button, it changes isOn from false to true, then does the appropriate action if it is true. But it’s not updating the button texture.

I put a breakpoint on the “isOn = true;” line in the if statement that checks for player collision, and it says that it is changing to true.

Also, I should mention that a seperate class reads a text file, and then adds all of the information onto an instance of this class, then is added to a list and loaded/updated/drawn properly.

So with that said, I’m fairly certain that it is the Draw() method that isn’t working properly.


        TriggerType Trigger;
        ActivatorType Activator;
        CommandType Command;

        public TriggerHandler(TriggerType trigger, ActivatorType activator, CommandType command, Point locationA, Point locationB, string layer, int cellIndex)
        {
            Trigger = trigger;
            Activator = activator;
            TriggerLocationA = locationA;
            TriggerLocationB = locationB;
            Layer = layer;
            tileIndex = cellIndex;
            Command = command;
        }

        public void LoadTriggerTextures(ContentManager content)
        {
            if (Activator == ActivatorType.FloorButton)
            {
                FloorButtonOn = content.Load<Texture2D>("Triggers/On/FloorButtonOn");
                FloorButtonOff = content.Load<Texture2D>("Triggers/Off/FloorButtonOff");
            }
        }

        public void Update(GameTime gt, TileMap tm)
        {
            Point playerCenter = tm.Player.Center;
            kbs = Keyboard.GetState();

            if (Trigger == TriggerType.Activator)
            {
                if (Command == Command.Replace)
                {
                    if (Activator == ActivatorType.FloorButton)
                    {
                        triggerRect = new Rectangle(TriggerLocationA.X * tm.TileWidth + (int)tm.position.X + 32, TriggerLocationA.Y * tm.TileHeight + (int)tm.position.Y + 16, 64, 64);

                        if (Layer.Equals("L2"))
                        {
                            if (triggerRect.Contains(playerCenter)) { isOn = true; }
                            else { isOn = false; }

                            if (isOn == true)
                            {
                                tm.SetL2CellIndex(TriggerLocationB, tileIndex);
                            }
                        }
                    }
                }
            }
        }

        public void Draw(SpriteBatch sb, TileMap tm)
        {
            drawingRect = new Rectangle(TriggerLocationA.X * tm.TileWidth + (int)tm.position.X, TriggerLocationA.Y * tm.TileHeight + (int)tm.position.Y, 128, 128);

            if (Activator == ActivatorType.FloorButton)
            {
                if (isOn == false)
                {
                    sb.Draw(FloorButtonOff, drawingRect, Color.White);
                }
                else if (isOn == true)
                {
                    sb.Draw(FloorButtonOn, drawingRect, Color.White);
                }
            }

            if (Activator == ActivatorType.FloorPullSwitch)
            {
                if (isOn == true)
                    sb.Draw(FloorPullSwitchIn, drawingRect, Color.White);
                else if (isOn == false)
                    sb.Draw(FloorPullSwitchOut, drawingRect, Color.White);
            }

            if (Change == ChangeMap.Texture)
            {
                sb.Draw(ChangeMapTexture, drawingRect, Color.White);
            }
        }

Also, changing the bool to static makes only the first button check for player collision, but also turns on all of the buttons. I’m not sure what I’m exactly doing wrong here.

You should use the debugger and step thru your code. This is certainly a simple logic bug.