Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

some problems with mouse click?

A topic by Magnus Oblerion created Dec 24, 2020 Views: 153 Replies: 1
Viewing posts 1 to 2
Submitted (2 edits)

i have problems with mouse click , when i press mouse 5 time --> it draw 13 time .

my code :

mouse = {
    x=0,
    y=0,   
    btng=0,--left btn
    btnd=0,--right btn             btnm=0,--mid btn
  init = function()
    poke(0x5f2d, 1)
  end,
  update = function()
    local x,y = stat(32)-1,stat(33)-1
    mouse.x,mouse.y = x,y
    if(stat(34)==0)then
        mouse.btng=0
        mouse.btnd=0
        mouse.btnm=0
    end
    if(stat(34)==1)then                  mouse.btng=1                  mouse.btnd=0
        mouse.btnm=0
    end         if(stat(34)==2)then                  mouse.btng=0                  mouse.btnd=1
        mouse.btnm=0
    end         if(stat(34)==4)then                  mouse.btng=0                  mouse.btnd=0
        mouse.btnm=1
    end   end
}
(+1)

I think the issue is that pico8 doesn’t do any debouncing for you, so mouse button presses are not aligned to game loop frames. You would need to keep track of the button state yourself to detect if it’s newly pressed in this frame or newly released.

Stat reference: https://pico-8.fandom.com/wiki/Stat#.7B30.E2.80.A636.7D_Mouse_and_keyboard_in_.22devkit_mode.22