/
example.script
77 lines (63 loc) · 2.69 KB
/
example.script
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
local world_scale = 0.01
function init(self)
msg.post(".", "acquire_input_focus")
if not fmod then
label.set_text("#label", "Sorry! Your platform is not yet supported.")
return
end
fmod.studio.system:load_bank_memory(resource.load("/example/banks/Master Bank.bank"), fmod.STUDIO_LOAD_BANK_NORMAL)
fmod.studio.system:load_bank_memory(resource.load("/example/banks/Master Bank.strings.bank"), fmod.STUDIO_LOAD_BANK_NORMAL)
fmod.studio.system:load_bank_memory(resource.load("/example/banks/Vehicles.bank"), fmod.STUDIO_LOAD_BANK_NORMAL)
-- You can alternatively use this path to load banks from your bundle_resources dir
print(sys.get_application_path())
local event_description = fmod.studio.system:get_event("event:/Vehicles/Basic Engine")
local event = event_description:create_instance()
self.event = event
-- Error handling example
local ok, err = pcall(function ()
fmod.studio.system:get_event("event:/Inexistent event")
end)
if not ok then
print(err)
local code = fmod.error_code[err] -- The FMOD error code (a number).
print(code)
if code == fmod.ERR_EVENT_NOTFOUND then
print("Ooops! This event doesn't exist!")
end
end
local listener_attr = fmod._3D_ATTRIBUTES()
self.listener_attr = listener_attr
listener_attr.position = go.get_world_position("listener") * world_scale
listener_attr.velocity = vmath.vector3(0.0)
listener_attr.forward = vmath.vector3(0.0, 1.0, 0.0)
listener_attr.up = vmath.vector3(0.0, 0.0, -1.0)
fmod.studio.system:set_listener_attributes(0, listener_attr)
local source_attr = fmod._3D_ATTRIBUTES()
self.source_attr = source_attr
source_attr.position = go.get_world_position("source") * world_scale
source_attr.velocity = vmath.vector3(0.0)
source_attr.forward = vmath.vector3(0.0, 1.0, 0.0)
source_attr.up = vmath.vector3(0.0, 0.0, -1.0)
event:set_3d_attributes(source_attr)
event:set_parameter_by_name("RPM", 650.0, false)
event:start()
end
local function update_attributes(attr, dt, new_position)
local delta_pos = new_position - attr.position
attr.position = new_position
attr.velocity = delta_pos * (1.0 / dt)
end
function update(self, dt)
if not fmod then return end
local listener_pos = go.get_world_position("listener") * world_scale
update_attributes(self.listener_attr, dt, listener_pos)
fmod.studio.system:set_listener_attributes(0, self.listener_attr)
local source_pos = go.get_world_position("source") * world_scale
update_attributes(self.source_attr, dt, source_pos)
self.event:set_3d_attributes(self.source_attr)
end
function on_input(self, action_id, action)
if action_id == hash("click") then
go.set_position(vmath.vector3(action.x, action.y, 0.0), "source")
end
end