-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.lua
68 lines (55 loc) · 1.51 KB
/
util.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
Util ={}
function Util:window(title, size)
MOAISim.openWindow(title, size.width,size.height)
end
function Util:viewport(size)
local viewport = MOAIViewport.new(size.width,size.height)
viewport:setSize(size.width,size.height)
viewport:setScale(size.width,size.height)
return viewport
end
textures = {}
function Util:texture(file_path)
local texture = textures[file_path]
if not texture then
local moai_texture = MOAITexture.new()
moai_texture:load(file_path)
local sizex, sizey = moai_texture:getSize()
textures[file_path] = {image = moai_texture, width = sizex, height = sizey}
texture = textures[file_path]
end
return texture
end
function Util:character(properties)
if not properties.file then
return nil -- TODO: Make a box
end
if not properties.scale then
properties.scale = 1
end
local gfxQuad = MOAIGfxQuad2D.new()
texture = Util:texture(properties.file)
gfxQuad:setTexture(texture.image)
-- local w,h = properties.width, properties.height
local w,h = texture.width, texture.height
gfxQuad:setRect(-w,-h,w,h)
prop = MOAIProp2D.new()
prop:setDeck(gfxQuad)
-- prop:setScl(properties.scale, properties.scale)
prop:setScl(properties.scale)
prop.scale = properties.scale
if properties.name then
prop.name = properties.name
else
prop.name = "Unnamed"
end
return prop
end
function Util:layer(viewport,on)
local layer = MOAILayer2D.new()
layer:setViewport(viewport)
if on then
MOAISim.pushRenderPass(layer)
end
return layer
end