Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by SnakePlissken

Ok my game has been progressing pretty smoothly lately but running into a problem with the input state of the mouse click sticking. Essentially I am capturing the mouse click to see if its pressed and then seeing if the pos.x and pos.y are in the grid that holds my entity.

This will work for the first time it fires however when trying to use this on a separate entity all I need to do is click anywhere and the mouse over to its location and it will fire the if statement.

So what would cause the .pressed state to hold up?

Here is the code that fires on click and in current entity grid.

            var currentXFloor;
            var currentYFloor;
            
            var CurrentXCeiling;
            var currentYCeiling;
            
            currentXFloor = this.pos.x;
            currentYFloor = this.pos.y;
            
            currentXCeiling = currentXFloor + 32;
            currentYCeiling = currentYFloor + 32;
            
            
            if((ig.input.pressed('click')) && (ig.input.mouse.y <= currentYCeiling && ig.input.mouse.y >= currentYFloor ) &&
               (ig.input.mouse.x <= currentXCeiling && ig.input.mouse.x >= currentXFloor) )
            {
                    // MY CODE
            }

1 decade ago by SnakePlissken

Not sure if i love or hate when this happens. I just figured out the problem. I had a variable that was being compared in the update of the entities and this variable was set to null. This in turn caused an error which I'm guessing caused the click to hold up and fire when it was not being clicked.

So if anyone else has this problem check your variables and error console.

1 decade ago by Graphikos

This is all the same issue as "click through"... but in reverse. I've solved this by tracking what has "focus" and ignore clicks if something else has focus. But sometimes its not that clear cut. It's been a topic brought up a few times.

http://impactjs.com/forums/help/i-writed-whether-entity-is-clicked-function-which-need-to-be-improved

I suggest using the snippet to handle click detection though (from the other topic)... won't solve your problem but it is a much cleaner way.

Edit: Oh yes, and always keep an eye on the error console. You will be running in circles without it! ;) In Chrome I use this extension to make it more obvious when there is an error.

https://chrome.google.com/extensions/detail/jafmfknfnkoekkdocjiaipcnmkklaajd
Page 1 of 1
« first « previous next › last »