-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.lua
63 lines (56 loc) · 1.2 KB
/
scene.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
----------------------------
-- Author: M. Utku Altinkaya
----------------------------
--Base class for all scenes
Scene = {}
function Scene:init()
end
function Scene:draw()
end
function Scene:update(dt)
end
function Scene:keypressed( key, unicode )
end
function Scene:keyreleased( key, unicode )
end
function Scene:mousepressed( x, y, button )
end
--Class of UI container scenes, manages ui elements
UIScene = Class(Scene)
function UIScene:init()
Scene.init(self)
self.ui = {}
end
--draw all ui elements
function UIScene:draw()
for i, ui in pairs(self.ui) do
ui:draw()
end
end
function UIScene:update(dt)
for i, ui in pairs(self.ui) do
ui:update(dt)
end
end
--pass mouse press event to memeber ui elements
function UIScene:mousepressed(x, y, button )
for name, ui in pairs(self.ui) do
if ui:mousepressed(x,y,button) then
self:buttonClick(name)
end
end
end
--pass mouse keypress event to memeber ui elements
function UIScene:keypressed( key, unicode )
for name, ui in pairs(self.ui) do
ui:keypressed(key, unicode)
end
end
--set color of ui elements
function UIScene:setColor(color)
for _,ui in pairs(self.ui) do
ui.color = color
ui.normalColor = color
end
end