-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile.lua
71 lines (57 loc) · 1.84 KB
/
tile.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
module (..., package.seeall)
-- local util = require("util")
function drawColorTile(tX, tY, tW, tH, sound, color)
local tile = display.newRect(tX, tY, tW, tH)
tile:setFillColor(color[1], color[2], color[3])
local tileGroup = display.newGroup()
tileGroup:insert(tile)
assignSound(tile, tileGroup, sound)
return tileGroup
end
function drawImageTile(tX, tY, tW, tH, sound, image, scalePercent, scaleAmplifier)
local tile = display.newImage(image, tX, tY)
tile:scale(scalePercent, scalePercent)
tile.width = tW * scaleAmplifier
tile.height = tH * scaleAmplifier
tile.xOrigin = tX + (tW / 2)
tile.yOrigin = tY + (tH / 2)
local tileGroup = display.newGroup()
tileGroup:insert(tile)
assignSound(tile, tileGroup, sound)
return tileGroup
end
function drawImageButtonTile(tX, tY, tW, tH, image, scalePercent, scaleAmplifier, directorInstance)
local tile = display.newImage(image, tX, tY)
tile:scale(scalePercent, scalePercent)
tile.width = tW * scaleAmplifier
tile.height = tH * scaleAmplifier
tile.xOrigin = tX + (tW / 2)
tile.yOrigin = tY + (tH / 2)
local tileGroup = display.newGroup()
tileGroup:insert(tile)
local function pressCreateButtonTile (event)
print(">>> press create")
if event.phase == "ended" then
print(">>> press create - ended")
director:changeScene ("create")
end
end
tileGroup:addEventListener ("touch", pressRed)
return tileGroup
end
-- TODO: After making OO, click to stop (toggling an is-playing instance var after playSound, removing the event handling and adding one to stop, and vice versa)
function assignSound(t, g, s)
if s == nil then
s = "noaudio.mp3"
end
local function pressTile (event)
print(">>> press tile")
-- util.print_r(t)
if event.phase == "ended" then
print(">>> press tile - ended")
media.stopSound()
media.playSound(s)
end
end
g:addEventListener("touch", pressTile)
end