新增一个简易秒表小程序
This commit is contained in:
@@ -647,6 +647,11 @@ local commands={}do
|
||||
scene='app_triple',
|
||||
description="A Match-3 Game. Original idea from Sanlitun / Triple Town"
|
||||
},
|
||||
{
|
||||
code="sw",
|
||||
scene='app_stopwatch',
|
||||
description="A stopwatch"
|
||||
},
|
||||
{
|
||||
code="spin",
|
||||
scene='app_spin',
|
||||
|
||||
70
parts/scenes/app_stopwatch.lua
Normal file
70
parts/scenes/app_stopwatch.lua
Normal file
@@ -0,0 +1,70 @@
|
||||
local state
|
||||
local pressTime
|
||||
local releaseTime
|
||||
local time1,time2
|
||||
|
||||
local function press()
|
||||
if state==0 then
|
||||
state=1
|
||||
pressTime=TIME()
|
||||
releaseTime=false
|
||||
time2=STRING.time(0)
|
||||
elseif state==2 then
|
||||
state=0
|
||||
end
|
||||
end
|
||||
|
||||
local function release()
|
||||
if state==1 then
|
||||
state=2
|
||||
releaseTime=TIME()
|
||||
end
|
||||
end
|
||||
|
||||
local scene={}
|
||||
|
||||
function scene.sceneInit()
|
||||
state=0
|
||||
time1=STRING.time(0)
|
||||
time2=STRING.time(0)
|
||||
end
|
||||
|
||||
function scene.mouseDown()
|
||||
press()
|
||||
end
|
||||
function scene.mouseUp()
|
||||
release()
|
||||
end
|
||||
function scene.keyDown(key,isRep)
|
||||
if isRep then return end
|
||||
if key=='escape'then
|
||||
SCN.back()
|
||||
else
|
||||
press()
|
||||
end
|
||||
end
|
||||
function scene.keyUp()
|
||||
release()
|
||||
end
|
||||
|
||||
function scene.update()
|
||||
if state~=0 then
|
||||
time1=STRING.time(TIME()-pressTime)
|
||||
if releaseTime then
|
||||
time2=STRING.time(TIME()-releaseTime)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function scene.draw()
|
||||
FONT.set(60)
|
||||
mStr(CHAR.icon.import,340,230)
|
||||
mStr(CHAR.icon.export,940,230)
|
||||
mStr(time1,340,300)
|
||||
mStr(time2,940,300)
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=60,fText=CHAR.icon.back,code=backScene},
|
||||
}
|
||||
return scene
|
||||
Reference in New Issue
Block a user