Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have an external class which reads the user's mouse clicks. I gave a position where the user have to click, and when the user clicks on that position, it would turn my boolean "mouse" to true. But when I connect that to my game(state based) class, it does not work.

Here's the code:

External class

public void UI(Input input, GameContainer gc, float posX, float posY)
    {
        int x = Mouse.getX();
        int y = Mouse.getY();
        if(posX<=100 && posY<=100)
        {
        if(Mouse.isButtonDown(1))
        {
            mouse = true;
        }
        }
    }

Game class(main)

public void update(GameContainer gc, StateBasedGame sbg, int delta)
            throws SlickException {
int x = Mouse.getX();
           int y = Mouse.getY();
                civ.UI(input, gc, x,y);
}

The problem is when I click my mouse at posX<=100 && posY<=100. It does not work.

share|improve this question
1  
What about it doesn't work? What are some example input and outputs for the program? You really need to work on your accept rate. – Byte56 Nov 23 '12 at 6:50
Your edit doesn't help; you should make some effort to debug code (since you're the best person to do it). Why doesn't it work...? isButtonDown is false, or do posX/posY not match the criteria? Perhaps the aren't checking the value of 'mouse' properly after the update? Lots of things can happen. Use the debugger or logging statements to determine what is happening (since this is Java I strongly recomment debugging with breakpoints since it's so easy). Probably you can find the solution yourself; if not, post your findings and maybe we can think of something. – Liosan Nov 23 '12 at 9:52
Of course, there is also the question why do need int x = Mouse.getX(); in the UI() method if you pass posX, posY as a parameter. – Liosan Nov 23 '12 at 10:18

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.