优化绘制虚拟按键的代码
This commit is contained in:
@@ -2,6 +2,9 @@ local tm=love.timer
|
|||||||
local data=love.data
|
local data=love.data
|
||||||
|
|
||||||
local fs=love.filesystem
|
local fs=love.filesystem
|
||||||
|
local gc=love.graphics
|
||||||
|
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
||||||
|
|
||||||
local int,rnd=math.floor,math.random
|
local int,rnd=math.floor,math.random
|
||||||
local sub=string.sub
|
local sub=string.sub
|
||||||
local char,byte=string.char,string.byte
|
local char,byte=string.char,string.byte
|
||||||
@@ -358,6 +361,50 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--Game draw
|
||||||
|
local VK=virtualkey
|
||||||
|
function drawVirtualKeys()
|
||||||
|
if SETTING.VKSwitch then
|
||||||
|
local a=SETTING.VKAlpha
|
||||||
|
local _
|
||||||
|
if SETTING.VKIcon then
|
||||||
|
local icons=TEXTURE.VKIcon
|
||||||
|
for i=1,#VK do
|
||||||
|
if VK[i].ava then
|
||||||
|
local B=VK[i]
|
||||||
|
gc_setColor(1,1,1,a)
|
||||||
|
gc.setLineWidth(B.r*.07)
|
||||||
|
gc_circle("line",B.x,B.y,B.r,10)--Button outline
|
||||||
|
_=VK[i].pressTime
|
||||||
|
gc_setColor(B.color[1],B.color[2],B.color[3],a)
|
||||||
|
gc.draw(icons[i],B.x,B.y,nil,B.r*.026+_*.08,nil,18,18)--Icon
|
||||||
|
if _>0 then
|
||||||
|
gc_setColor(1,1,1,a*_*.08)
|
||||||
|
gc_circle("fill",B.x,B.y,B.r*.94,10)--Glow when press
|
||||||
|
gc_circle("line",B.x,B.y,B.r*(1.4-_*.04),10)--Ripple
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for i=1,#VK do
|
||||||
|
if VK[i].ava then
|
||||||
|
local B=VK[i]
|
||||||
|
gc_setColor(1,1,1,a)
|
||||||
|
gc.setLineWidth(B.r*.07)
|
||||||
|
gc_circle("line",B.x,B.y,B.r,10)
|
||||||
|
_=VK[i].pressTime
|
||||||
|
if _>0 then
|
||||||
|
gc_setColor(1,1,1,a*_*.08)
|
||||||
|
gc_circle("fill",B.x,B.y,B.r*.94,10)
|
||||||
|
gc_circle("line",B.x,B.y,B.r*(1.4-_*.04),10)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--Game
|
--Game
|
||||||
function generateLine(hole)
|
function generateLine(hole)
|
||||||
-- return 2^10-1-2^(hole-1)
|
-- return 2^10-1-2^(hole-1)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
local data=love.data
|
local data=love.data
|
||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
|
||||||
local tc=love.touch
|
local tc=love.touch
|
||||||
|
|
||||||
local playerData
|
local playerData
|
||||||
@@ -384,7 +383,7 @@ function scene.draw()
|
|||||||
local t=TIME()
|
local t=TIME()
|
||||||
if MARKING then
|
if MARKING then
|
||||||
setFont(25)
|
setFont(25)
|
||||||
gc_setColor(1,1,1,.2+.1*(sin(3*t)+sin(2.6*t)))
|
gc.setColor(1,1,1,.2+.1*(sin(3*t)+sin(2.6*t)))
|
||||||
mStr(text.marking,190,60+26*sin(t))
|
mStr(text.marking,190,60+26*sin(t))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -394,44 +393,7 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Virtual keys
|
--Virtual keys
|
||||||
if SETTING.VKSwitch then
|
drawVirtualKeys()
|
||||||
local a=SETTING.VKAlpha
|
|
||||||
local _
|
|
||||||
if SETTING.VKIcon then
|
|
||||||
local icons=TEXTURE.VKIcon
|
|
||||||
for i=1,#VK do
|
|
||||||
if VK[i].ava then
|
|
||||||
local B=VK[i]
|
|
||||||
gc_setColor(1,1,1,a)
|
|
||||||
gc.setLineWidth(B.r*.07)
|
|
||||||
gc_circle("line",B.x,B.y,B.r,10)--Button outline
|
|
||||||
_=VK[i].pressTime
|
|
||||||
gc_setColor(B.color[1],B.color[2],B.color[3],a)
|
|
||||||
gc.draw(icons[i],B.x,B.y,nil,B.r*.026+_*.08,nil,18,18)--Icon
|
|
||||||
if _>0 then
|
|
||||||
gc_setColor(1,1,1,a*_*.08)
|
|
||||||
gc_circle("fill",B.x,B.y,B.r*.94,10)--Glow when press
|
|
||||||
gc_circle("line",B.x,B.y,B.r*(1.4-_*.04),10)--Ripple
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i=1,#VK do
|
|
||||||
if VK[i].ava then
|
|
||||||
local B=VK[i]
|
|
||||||
gc_setColor(1,1,1,a)
|
|
||||||
gc.setLineWidth(B.r*.07)
|
|
||||||
gc_circle("line",B.x,B.y,B.r,10)
|
|
||||||
_=VK[i].pressTime
|
|
||||||
if _>0 then
|
|
||||||
gc_setColor(1,1,1,a*_*.08)
|
|
||||||
gc_circle("fill",B.x,B.y,B.r*.94,10)
|
|
||||||
gc_circle("line",B.x,B.y,B.r*(1.4-_*.04),10)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Warning
|
--Warning
|
||||||
gc.push("transform")
|
gc.push("transform")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local gc_setColor,gc_circle=gc.setColor,gc.circle
|
local gc_setColor=gc.setColor
|
||||||
local tc=love.touch
|
local tc=love.touch
|
||||||
|
|
||||||
local max,sin=math.max,math.sin
|
local max,sin=math.max,math.sin
|
||||||
@@ -265,10 +265,10 @@ local function drawAtkPointer(x,y)
|
|||||||
t=sin(t*20)
|
t=sin(t*20)
|
||||||
|
|
||||||
gc_setColor(.2,.7+t*.2,1,.6+t*.4)
|
gc_setColor(.2,.7+t*.2,1,.6+t*.4)
|
||||||
gc_circle("fill",x,y,25,6)
|
gc.circle("fill",x,y,25,6)
|
||||||
|
|
||||||
gc_setColor(0,.6,1,.8-a)
|
gc_setColor(0,.6,1,.8-a)
|
||||||
gc_circle("line",x,y,30*(1+a),6)
|
gc.circle("line",x,y,30*(1+a),6)
|
||||||
end
|
end
|
||||||
function scene.draw()
|
function scene.draw()
|
||||||
local t=TIME()
|
local t=TIME()
|
||||||
@@ -284,44 +284,7 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Virtual keys
|
--Virtual keys
|
||||||
if SETTING.VKSwitch then
|
drawVirtualKeys()
|
||||||
local a=SETTING.VKAlpha
|
|
||||||
local _
|
|
||||||
if SETTING.VKIcon then
|
|
||||||
local icons=TEXTURE.VKIcon
|
|
||||||
for i=1,#VK do
|
|
||||||
if VK[i].ava then
|
|
||||||
local B=VK[i]
|
|
||||||
gc_setColor(1,1,1,a)
|
|
||||||
gc.setLineWidth(B.r*.07)
|
|
||||||
gc_circle("line",B.x,B.y,B.r,10)--Button outline
|
|
||||||
_=VK[i].pressTime
|
|
||||||
gc_setColor(B.color[1],B.color[2],B.color[3],a)
|
|
||||||
gc.draw(icons[i],B.x,B.y,nil,B.r*.026+_*.08,nil,18,18)--Icon
|
|
||||||
if _>0 then
|
|
||||||
gc_setColor(1,1,1,a*_*.08)
|
|
||||||
gc_circle("fill",B.x,B.y,B.r*.94,10)--Glow when press
|
|
||||||
gc_circle("line",B.x,B.y,B.r*(1.4-_*.04),10)--Ripple
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i=1,#VK do
|
|
||||||
if VK[i].ava then
|
|
||||||
local B=VK[i]
|
|
||||||
gc_setColor(1,1,1,a)
|
|
||||||
gc.setLineWidth(B.r*.07)
|
|
||||||
gc_circle("line",B.x,B.y,B.r,10)
|
|
||||||
_=VK[i].pressTime
|
|
||||||
if _>0 then
|
|
||||||
gc_setColor(1,1,1,a*_*.08)
|
|
||||||
gc_circle("fill",B.x,B.y,B.r*.94,10)
|
|
||||||
gc_circle("line",B.x,B.y,B.r*(1.4-_*.04),10)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Attacking & Being attacked
|
--Attacking & Being attacked
|
||||||
if GAME.modeEnv.royaleMode then
|
if GAME.modeEnv.royaleMode then
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ function scene.touchMove(_,_,_,dx,dy)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function VirtualkeyPreview()
|
local function virtualkeyPreview()
|
||||||
if SETTING.VKSwitch then
|
if SETTING.VKSwitch then
|
||||||
for i=1,#VK_org do
|
for i=1,#VK_org do
|
||||||
local B=VK_org[i]
|
local B=VK_org[i]
|
||||||
@@ -80,7 +80,8 @@ local function VirtualkeyPreview()
|
|||||||
gc.circle("fill",B.x,B.y,B.r,10)
|
gc.circle("fill",B.x,B.y,B.r,10)
|
||||||
end
|
end
|
||||||
if SETTING.VKIcon then
|
if SETTING.VKIcon then
|
||||||
gc.setColor(B.color[1],B.color[2],B.color[3],SETTING.VKAlpha)
|
local c=B.color
|
||||||
|
gc.setColor(c[1],c[2],c[3],SETTING.VKAlpha)
|
||||||
gc.draw(TEXTURE.VKIcon[i],B.x,B.y,nil,B.r*.025,nil,18,18)
|
gc.draw(TEXTURE.VKIcon[i],B.x,B.y,nil,B.r*.025,nil,18,18)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -91,7 +92,7 @@ function scene.draw()
|
|||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
gc.setLineWidth(7)gc.rectangle("line",340,15,600,690)
|
gc.setLineWidth(7)gc.rectangle("line",340,15,600,690)
|
||||||
gc.setLineWidth(3)gc.rectangle("line",490,85,300,600)
|
gc.setLineWidth(3)gc.rectangle("line",490,85,300,600)
|
||||||
VirtualkeyPreview()
|
virtualkeyPreview()
|
||||||
local d=snapUnit
|
local d=snapUnit
|
||||||
if d>=10 then
|
if d>=10 then
|
||||||
gc.setLineWidth(3)
|
gc.setLineWidth(3)
|
||||||
|
|||||||
Reference in New Issue
Block a user