FBA The Creator
http://www.fbacreator.com/fbaforum/

Is there a way of clearing the mousedown buffer?
http://www.fbacreator.com/fbaforum/viewtopic.php?f=5&t=63
Page 1 of 1

Author:  Boiled Sweets [ Thu Jun 26, 2008 12:16 pm ]
Post subject:  Is there a way of clearing the mousedown buffer?

Hi,

adding a menu to my game. On the main menu page I have amongst others an "options" & "quit" button. When they click "quit" the game closes. When they click "options" the options pages is displayed.

On the options page in the same position as the quit button there a "done" button to return them to the main page.

It all works lovely but if I don't 'stab' the "done" button then the "quit" button event is triggered. So is there a way to clear the mousedown buffer so that I can be sure they actually pressed the "quit" button deliberately?
Code:
function DoMenu()

        drawimage(splash1, 0,0)

        -- MAIN PAGE
       
        if MENU_PAGE == 1 then
       
       
                drawimage(btn_start, SCREEN_CENTRE_X - (BUTTON_WIDTH/2),120)
                drawimage(btn_options, SCREEN_CENTRE_X - (BUTTON_WIDTH/2),160)
                drawimage(btn_quit,  SCREEN_CENTRE_X - (BUTTON_WIDTH/2),240)
         
                if blend > 0 then
                        fadescreen()
                        blend = blend - FADE_SPEED_IN
                end
       
                -- START       
                if mousein(SCREEN_CENTRE_X - (BUTTON_WIDTH/2), 120, SCREEN_CENTRE_X - (BUTTON_WIDTH/2)+BUTTON_WIDTH, 120+32) then     
               
                        if (mousedown() > 0) then
                                BLOCK_SIZE = 16
                                BLOCK_OFFSET = BLOCK_SIZE / 2
                                CURRENT_STATE = STATE_MENU_FADEOUT
                                LoadGame()
                        end
                end
       
                -- OPTIONS
                if mousein(SCREEN_CENTRE_X - (BUTTON_WIDTH/2), 160, SCREEN_CENTRE_X - (BUTTON_WIDTH/2)+BUTTON_WIDTH, 160+32) then     
               
                        if (mousedown() > 0) then
                                MENU_PAGE = 2
                        end
                end
       
                -- QUIT
                if mousein(SCREEN_CENTRE_X - (BUTTON_WIDTH/2), 240, SCREEN_CENTRE_X - (BUTTON_WIDTH/2)+BUTTON_WIDTH, 240+32) then     
               
                        if (mousedown() > 0) then
                                CURRENT_STATE = STATE_QUIT_FADEOUT
                        end
                end


        -- OPTIONS PAGE
       
        elseif MENU_PAGE == 2 then

                drawimage(btn_done,  SCREEN_CENTRE_X - (BUTTON_WIDTH/2),240)

                -- DONE
               
                if mousein(SCREEN_CENTRE_X - (BUTTON_WIDTH/2), 240, SCREEN_CENTRE_X - (BUTTON_WIDTH/2)+BUTTON_WIDTH, 240+32) then     
               
                        if (mousedown() > 0) then
                                MENU_PAGE = 1
                        end
                end

        end

end


Author:  evilmaio [ Thu Jun 26, 2008 12:37 pm ]
Post subject:  Re: Is there a way of clearing the mousedown buffer?

Actually there isn't a way to do that, you could workaround this using the stylus events, instead of checking the mouse position inside your logic.

Author:  Boiled Sweets [ Thu Jun 26, 2008 12:51 pm ]
Post subject:  Re: Is there a way of clearing the mousedown buffer?

Was just following the examples given with FBA....

Author:  evilmaio [ Thu Jun 26, 2008 12:57 pm ]
Post subject:  Re: Is there a way of clearing the mousedown buffer?

I know, but for your case, with alternate pages and several buttons on same position, it won't work well :)
I thought a reset function for mousedown counter wouldn't be useful, but i'll add it if it will be necessary :)

Author:  Boiled Sweets [ Thu Jun 26, 2008 1:00 pm ]
Post subject:  Re: Is there a way of clearing the mousedown buffer?

Hi,

well more functionality would be nice :-)

But I have recoded...

Code:
function onstylusdown(x,y)

        if CURRENT_STATE == STATE_MENU then

                if MENU_PAGE == 1 then
                        if mousein(SCREEN_CENTRE_X - (BUTTON_WIDTH/2), 240, SCREEN_CENTRE_X - (BUTTON_WIDTH/2)+BUTTON_WIDTH, 240+32) then     
                                CURRENT_STATE = STATE_QUIT_FADEOUT
                        end
               
                elseif MENU_PAGE == 2 then
               
                        if mousein(SCREEN_CENTRE_X - (BUTTON_WIDTH/2), 240, SCREEN_CENTRE_X - (BUTTON_WIDTH/2)+BUTTON_WIDTH, 240+32) then     
               
                                MENU_PAGE = 1
                        end
               
                end
               
        end

     
end



and works perfectly - THANKS!

Yeah I could use the x, y passed to in see if it's inside the button are but easier to call mousein I think...

Author:  phrebh [ Thu Jun 26, 2008 1:01 pm ]
Post subject:  Re: Is there a way of clearing the mousedown buffer?

I use context-sensitive menus in the program I'm writing, and to make sure that my clicks are going to the write menu, I use some state variables. I got the idea from the Enlight code, where there are different states for the game, the help, and the about screen.

Here's a snippet:
Code:
  elseif mousein(49,96,166,111) then
    -- show info
    if HELP_MENU_CLICKED == 1 then
      HELP_INFO_CLICKED = 1
      HELP_MENU_CLICKED = 0
      MAINSCREEN_SHOWN = false
    end
  elseif mousein(49,112,166,130) then
    -- show about
    if HELP_MENU_CLICKED == 1 then
      HELP_ABOUT_CLICKED = 1
      HELP_MENU_CLICKED = 0
      MAINSCREEN_SHOWN = false
    end


You can see that I check the state of the screen before I allow the click to change anything else.

Author:  Boiled Sweets [ Thu Jun 26, 2008 1:02 pm ]
Post subject:  Re: Is there a way of clearing the mousedown buffer?

Don't take this the wrong way but I think that method is a little more 'clunky' - THANKS anyhow...

Author:  phrebh [ Thu Jun 26, 2008 1:13 pm ]
Post subject:  Re: Is there a way of clearing the mousedown buffer?

Oh, I see. You took the same concept but switched around the order of the ifs. I like it.

Author:  Boiled Sweets [ Thu Jun 26, 2008 1:18 pm ]
Post subject:  Re: Is there a way of clearing the mousedown buffer?

Also notice the const I'm using (the variables in uppercase). Makes it LOADS easier to rearrange the layout as it's all calculated based upon the certain set values - more flexible than hard coding...

Yet to set the button size, i.e. the 32 etc but I'm working flat out :-)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/