TEXT模块会生成文本对象用于绘制
优化绘制方式,略微提升性能
This commit is contained in:
@@ -1,80 +1,100 @@
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local gc_getColor,gc_setColor,gc_push,gc_pop=gc.getColor,gc.setColor,gc.push,gc.pop
|
local getColor,setColor=gc.getColor,gc.setColor
|
||||||
local gc_translate,gc_scale,gc_rotate,gc_shear=gc.translate,gc.scale,gc.rotate,gc.shear
|
|
||||||
|
|
||||||
local int,rnd=math.floor,math.random
|
local int,rnd=math.floor,math.random
|
||||||
local ins,rem=table.insert,table.remove
|
local ins,rem=table.insert,table.remove
|
||||||
local mStr=mStr
|
local getFont=FONT.get
|
||||||
|
local draw=gc.draw
|
||||||
|
|
||||||
local texts={}
|
local texts={}
|
||||||
|
|
||||||
local textFX={}
|
local textFX={}
|
||||||
function textFX.appear(t)
|
function textFX.appear(t)
|
||||||
mStr(t.text,t.x,t.y-t.font*.7)
|
draw(
|
||||||
|
t.text,t.x,t.y,
|
||||||
|
nil,
|
||||||
|
nil,nil,
|
||||||
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
|
)
|
||||||
end
|
end
|
||||||
function textFX.sudden(t)
|
function textFX.sudden(t)
|
||||||
gc_setColor(1,1,1,1-t.c)
|
setColor(1,1,1,1-t.c)
|
||||||
mStr(t.text,t.x,t.y-t.font*.7)
|
draw(
|
||||||
|
t.text,t.x,t.y,
|
||||||
|
nil,
|
||||||
|
nil,nil,
|
||||||
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
|
)
|
||||||
end
|
end
|
||||||
function textFX.fly(t)
|
function textFX.fly(t)
|
||||||
mStr(t.text,t.x+(t.c-.5)^3*300,t.y-t.font*.7)
|
draw(
|
||||||
|
t.text,t.x+(t.c-.5)^3*300,t.y,
|
||||||
|
nil,
|
||||||
|
nil,nil,
|
||||||
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
|
)
|
||||||
end
|
end
|
||||||
function textFX.stretch(t)
|
function textFX.stretch(t)
|
||||||
gc_push('transform')
|
draw(
|
||||||
gc_translate(t.x,t.y)
|
t.text,t.x,t.y,
|
||||||
if t.c<.3 then
|
nil,
|
||||||
gc_scale((.3-t.c)*1.6+1,1)
|
t.c<.3 and(.3-t.c)*1.6+1 or 1,1,
|
||||||
end
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
mStr(t.text,0,-t.font*.7)
|
)
|
||||||
gc_pop()
|
|
||||||
end
|
end
|
||||||
function textFX.drive(t)
|
function textFX.drive(t)
|
||||||
gc_push('transform')
|
draw(
|
||||||
gc_translate(t.x,t.y)
|
t.text,t.x,t.y,
|
||||||
if t.c<.3 then
|
nil,
|
||||||
gc_shear((.3-t.c)*2,0)
|
nil,nil,
|
||||||
end
|
t.text:getWidth()*.5,t.text:getHeight()*.5,
|
||||||
mStr(t.text,0,-t.font*.7)
|
t.c<.3 and (.3-t.c)*2 or 0,0
|
||||||
gc_pop()
|
)
|
||||||
end
|
end
|
||||||
function textFX.spin(t)
|
function textFX.spin(t)
|
||||||
gc_push('transform')
|
draw(
|
||||||
gc_translate(t.x,t.y)
|
t.text,t.x,t.y,
|
||||||
if t.c<.3 then
|
t.c<.3 and (.3-t.c)^2*4 or t.c<.8 and 0 or (t.c-.8)^2*-4,
|
||||||
gc_rotate((.3-t.c)^2*4)
|
nil,nil,
|
||||||
elseif t.c>.8 then
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
gc_rotate((t.c-.8)^2*-4)
|
)
|
||||||
end
|
|
||||||
mStr(t.text,0,-t.font*.7)
|
|
||||||
gc_pop()
|
|
||||||
end
|
end
|
||||||
function textFX.flicker(t)
|
function textFX.flicker(t)
|
||||||
local _,_,_,T=gc_getColor()
|
local _,_,_,T=getColor()
|
||||||
gc_setColor(1,1,1,T*(rnd()+.5))
|
setColor(1,1,1,T*(rnd()+.5))
|
||||||
mStr(t.text,t.x,t.y-t.font*.7)
|
draw(
|
||||||
|
t.text,t.x,t.y,
|
||||||
|
nil,
|
||||||
|
nil,nil,
|
||||||
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
|
)
|
||||||
end
|
end
|
||||||
function textFX.zoomout(t)
|
function textFX.zoomout(t)
|
||||||
gc_push('transform')
|
draw(
|
||||||
local k=t.c^.5*.1+1
|
t.text,t.x,t.y,
|
||||||
gc_translate(t.x,t.y)
|
nil,
|
||||||
gc_scale(k,k)
|
t.c^.5*.1+1,nil,
|
||||||
mStr(t.text,0,-t.font*.7)
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
gc_pop()
|
)
|
||||||
end
|
end
|
||||||
function textFX.beat(t)
|
function textFX.beat(t)
|
||||||
gc_push('transform')
|
local k=t.c<.3 and 1.3-t.c^2/.3 or 1
|
||||||
gc_translate(t.x,t.y)
|
draw(
|
||||||
if t.c<.3 then
|
t.text,t.x,t.y,
|
||||||
local k=1.3-t.c^2/.3
|
nil,
|
||||||
gc_scale(k,k)
|
k,k,
|
||||||
end
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
mStr(t.text,0,-t.font*.7)
|
)
|
||||||
gc_pop()
|
|
||||||
end
|
end
|
||||||
function textFX.score(t)
|
function textFX.score(t)
|
||||||
local _,_,_,T=gc_getColor()
|
local _,_,_,T=getColor()
|
||||||
gc_setColor(1,1,1,T*.5)
|
setColor(1,1,1,T*.5)
|
||||||
mStr(t.text,t.x,t.y-t.font*.7-t.c^.2*50)
|
draw(
|
||||||
|
t.text,t.x,t.y-0-t.c^.2*50,
|
||||||
|
nil,
|
||||||
|
nil,nil,
|
||||||
|
t.text:getWidth()*.5,t.text:getHeight()*.5
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local TEXT={}
|
local TEXT={}
|
||||||
@@ -83,23 +103,21 @@ function TEXT.clear()
|
|||||||
end
|
end
|
||||||
function TEXT.show(text,x,y,font,style,spd,stop)
|
function TEXT.show(text,x,y,font,style,spd,stop)
|
||||||
ins(texts,{
|
ins(texts,{
|
||||||
c=0, --Timer
|
c=0, --Timer
|
||||||
text=text, --String
|
text=gc.newText(getFont(int(font/5)*5 or 40),text), --String
|
||||||
x=x or 0, --X
|
x=x or 0, --X
|
||||||
y=y or 0, --Y
|
y=y or 0, --Y
|
||||||
font=int(font/5)*5 or 40,--Font
|
spd=(spd or 1)/60, --Timing speed(1=last 1 sec)
|
||||||
spd=(spd or 1)/60, --Timing speed(1=last 1 sec)
|
stop=stop, --Stop time(sustained text)
|
||||||
stop=stop, --Stop time(sustained text)
|
|
||||||
draw=assert(textFX[style or'appear'],"no text type:"..style),--Draw method
|
draw=assert(textFX[style or'appear'],"no text type:"..style),--Draw method
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
function TEXT.getText(text,x,y,font,style,spd,stop)--Another version of TEXT.show(), but only return text object, need manual management
|
function TEXT.getText(text,x,y,font,style,spd,stop)--Another version of TEXT.show(), but only return text object, need manual management
|
||||||
return{
|
return{
|
||||||
c=0,
|
c=0,
|
||||||
text=text,
|
text=gc.newText(getFont(int(font/5)*5 or 40),text),
|
||||||
x=x or 0,
|
x=x or 0,
|
||||||
y=y or 0,
|
y=y or 0,
|
||||||
font=int(font/5)*5 or 40,
|
|
||||||
spd=(spd or 1)/60,
|
spd=(spd or 1)/60,
|
||||||
stop=stop,
|
stop=stop,
|
||||||
draw=textFX[style or'appear']or error("unavailable type:"..style),
|
draw=textFX[style or'appear']or error("unavailable type:"..style),
|
||||||
@@ -129,8 +147,7 @@ function TEXT.draw(list)
|
|||||||
for i=1,#list do
|
for i=1,#list do
|
||||||
local t=list[i]
|
local t=list[i]
|
||||||
local p=t.c
|
local p=t.c
|
||||||
gc_setColor(1,1,1,p<.2 and p*5 or p<.8 and 1 or 5-p*5)
|
setColor(1,1,1,p<.2 and p*5 or p<.8 and 1 or 5-p*5)
|
||||||
FONT.set(t.font)
|
|
||||||
t:draw()
|
t:draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user