Button not recognizing different number of presses
Posted: Sun Apr 09, 2023 9:02 pm
The following is the function I am using to create the button:
And the implementation in the code:
I've used this same style of implementation before, for buttons without the touches parameter and it worked as I wanted it. Is there anything I'm missing with the touches thing? It's possible I've just been missing something obvious but I hope that's not it. Thanks!
Code: Select all
function gui.addIconButton2TouchSupport(px,py,onpress,onpress2,col,icon,sw,sh) --pos, size, function to excec when button is clicked, color, icon as love image, optional w/h
local ico=icon or''
local btncol=col or{1,1,1}
local btn={
p={x=px,y=py},
s={w=icon:getWidth()or sw,h=icon:getHeight()or sh},
pressed=onpress,
pressed2=onpress2,
onmouse=function(self,x,y,btn,istouch,touches)
if(x>self.p.x and x<self.p.x+self.s.w
and y>self.p.y and y<self.p.y+self.s.h)then
if(touches==1)then
self:pressed()
elseif(touches==2)then
self:pressed2()
end
end
end,
update=function(self)
return
end,
draw=function(self)
love.graphics.setColor(btncol)
love.graphics.draw(icon,self.p.x,self.p.y)
love.graphics.setColor(1,1,1,1)
end
}
return btn --returns button object, add to guiobj/world table
end
Code: Select all
gui.addIconButton2TouchSupport(love.graphics.getWidth()-cross:getWidth()*4,love.graphics.getHeight()-cross:getHeight(), -- transform/translate
function(self,x,y,btn,istouch,touches)
if(not imgTransformTranslate.iterate and currentImg.img~=nil)then
imgTransformTranslate.iterate=true
else
imgTransformTranslate.iterate=false
end
end,
function(self,x,y,btn,istouch,touches)
currentImg.rads=0
currentImg.scaleX,currentImg.scaleY=1,1
currentImg.x,currentImg.y=0,0
end,
{224/255,203/255,224/255,1},love.graphics.newImage('graphics/ui/larger.png'))