-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTKApplication.lua
93 lines (72 loc) · 2.23 KB
/
TKApplication.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
module(..., package.seeall)
local TKScreen = require( 'terevaka/TKScreen' )
require( 'math' )
-- TKApplication prototype
TKApplication = {}
-- TKApplication constructor
function TKApplication:new ( o )
o = o or {}
setmetatable ( o, self )
self.__index = self
return o
end
function TKApplication:setupSim ()
-- Setup sim
local scale = MOAIEnvironment.simulatorScale or 1
MOAISim.openWindow ( "test", TKScreen.SCREEN_WIDTH/scale, TKScreen.SCREEN_HEIGHT/scale )
MOAISim.setListener( MOAISim.EVENT_RESUME, function () self:onResume () end )
MOAISim.setListener( MOAISim.EVENT_PAUSE, function () self:onPause () end )
-- Make graphics smooth
-- MOAISim.setStep ( 1 / 60 )
-- MOAISim.clearLoopFlags ()
-- MOAISim.setLoopFlags( MOAISim.LOOP_FLAGS_FIXED )
-- Init viewport
self.viewport = TKScreen.viewport( TKScreen.SCREEN_WIDTH, TKScreen.SCREEN_HEIGHT, scale )
-- Subscribe touches
self:subscribeTouches ()
end
function TKApplication:initWithScene( scene, loadSceneParams )
-- User constructor
self:setupSim ()
self:onCreate ()
self:loadScene ( scene, loadSceneParams )
self:onResume()
return self
end
function TKApplication:loadScene ( scene, loadSceneParams )
self.currentScene = scene
for i, layer in pairs ( scene:getRenderTable ()) do
layer:setViewport ( self.viewport )
end
MOAIRenderMgr.setRenderTable ( scene:getRenderTable ())
scene:onLoadScene ( loadSceneParams )
end
function TKApplication:replaceScene ( scene, loadSceneParams )
self.currentScene:onRemoveScene ()
self:loadScene ( scene, loadSceneParams )
end
function TKApplication:subscribeTouches ()
TKScreen.subscribeTouches (
function ( dipX, dipY, rawX, rawY )
if self.currentScene then
self.currentScene:onTouch ( dipX, dipY, rawX, rawY )
end
end )
end
function TKApplication:onCreate ()
end
function TKApplication:onPause ()
end
function TKApplication:onResume ()
end
local app
function TKApplication:getSharedApp ()
if app == nil then
print('init application first!')
end
return app
end
function TKApplication:setSharedApp ( application )
app = application
end
return TKApplication