整理虚拟按键碰撞相关代码,调整碰撞力度
This commit is contained in:
@@ -420,26 +420,30 @@ function onVirtualkey(x,y)
|
|||||||
return nearest
|
return nearest
|
||||||
end
|
end
|
||||||
function pressVirtualkey(t,x,y)
|
function pressVirtualkey(t,x,y)
|
||||||
|
local SETTING=SETTING
|
||||||
local B=VK[t]
|
local B=VK[t]
|
||||||
B.isDown=true
|
B.isDown=true
|
||||||
B.pressTime=10
|
B.pressTime=10
|
||||||
if SETTING.VKTrack then
|
if SETTING.VKTrack then
|
||||||
if SETTING.VKDodge then--Button collision (not accurate)
|
--Auto follow
|
||||||
for i=1,#VK do
|
|
||||||
local b=VK[i]
|
|
||||||
local d=B.r+b.r-((B.x-b.x)^2+(B.y-b.y)^2)^.5--Hit depth(Neg means distance)
|
|
||||||
if d>0 then
|
|
||||||
b.x=b.x+(b.x-B.x)*d*b.r*5e-4
|
|
||||||
b.y=b.y+(b.y-B.y)*d*b.r*5e-4
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local O=VK_org[t]
|
local O=VK_org[t]
|
||||||
local _FW,_CW=SETTING.VKTchW,1-SETTING.VKCurW
|
local _FW,_CW=SETTING.VKTchW,1-SETTING.VKCurW
|
||||||
local _OW=1-_FW-_CW
|
local _OW=1-_FW-_CW
|
||||||
|
--(finger+current+origin)
|
||||||
|
B.x=x*_FW+B.x*_CW+O.x*_OW
|
||||||
|
B.y=y*_FW+B.y*_CW+O.y*_OW
|
||||||
|
|
||||||
--Auto follow: finger, current, origin (weight from setting)
|
--Button collision (not accurate)
|
||||||
B.x,B.y=x*_FW+B.x*_CW+O.x*_OW,y*_FW+B.y*_CW+O.y*_OW
|
if SETTING.VKDodge then
|
||||||
|
for i=1,#VK do
|
||||||
|
local b=VK[i]
|
||||||
|
local d=B.r+b.r-((B.x-b.x)^2+(B.y-b.y)^2)^.5--Hit depth(Neg means distance)
|
||||||
|
if d>0 then
|
||||||
|
b.x=b.x+(b.x-B.x)*d*b.r*6.2e-5
|
||||||
|
b.y=b.y+(b.y-B.y)*d*b.r*6.2e-5
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
SFX.play("virtualKey",SETTING.VKSFX)
|
SFX.play("virtualKey",SETTING.VKSFX)
|
||||||
VIB(SETTING.VKVIB)
|
VIB(SETTING.VKVIB)
|
||||||
|
|||||||
@@ -35,19 +35,14 @@ local function onVK_org(x,y)
|
|||||||
end
|
end
|
||||||
function scene.mouseDown(x,y,k)
|
function scene.mouseDown(x,y,k)
|
||||||
if k==2 then SCN.back()end
|
if k==2 then SCN.back()end
|
||||||
selected=onVK_org(x,y)or selected
|
scene.touchDown(x,y)
|
||||||
end
|
|
||||||
function scene.mouseMove(_,_,dx,dy)
|
|
||||||
if selected and ms.isDown(1)and not WIDGET.sel then
|
|
||||||
local B=VK_org[selected]
|
|
||||||
B.x,B.y=B.x+dx,B.y+dy
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
function scene.mouseUp()
|
function scene.mouseUp()
|
||||||
if selected then
|
scene.touchUp()
|
||||||
local B=VK_org[selected]
|
end
|
||||||
local k=snapUnit
|
function scene.mouseMove(_,_,dx,dy)
|
||||||
B.x,B.y=int(B.x/k+.5)*k,int(B.y/k+.5)*k
|
if ms.isDown(1)then
|
||||||
|
scene.touchMove(nil,nil,dx,dy)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.touchDown(x,y)
|
function scene.touchDown(x,y)
|
||||||
|
|||||||
Reference in New Issue
Block a user