-
Notifications
You must be signed in to change notification settings - Fork 0
/
06-draw-lines.lua
45 lines (35 loc) · 1 KB
/
06-draw-lines.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
MOAISim.openWindow ( "drawtest", 320, 480 )
viewport = MOAIViewport.new ()
viewport:setSize ( 320, 480 )
viewport:setScale ( 320, 480 )
layer = MOAILayer2D.new ()
layer:setViewport ( viewport )
MOAISim.pushRenderPass ( layer )
points = { 0, 0 }
function onDraw ( index, xOff, yOff, xFlip, yFlip )
MOAIDraw.drawLine ( unpack ( points ) )
lastX = mouseX
lastY = mouseY
end
mouseX = 0
mouseY = 0
lastX = 0
lastY = 0
function pointerCallback ( x, y )
mouseX, mouseY = layer:wndToWorld ( x, y )
end
MOAIInputMgr.device.pointer:setCallback ( pointerCallback )
function clickCallback( down )
if down then
table.insert ( points, mouseX )
table.insert ( points, mouseY )
print("mouseX:", mouseX, " mouseY:", mouseY)
end
end
MOAIInputMgr.device.mouseLeft:setCallback ( clickCallback )
scriptDeck = MOAIScriptDeck.new ()
scriptDeck:setRect ( -64, -64, 64, 64 )
scriptDeck:setDrawCallback ( onDraw )
prop = MOAIProp2D.new ()
prop:setDeck ( scriptDeck )
layer:insertProp ( prop )