@defold-typescript/types 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-availability.json +307 -307
- package/api-signatures.json +1311 -0
- package/api-targets.json +342 -0
- package/examples/translations.json +1984 -0
- package/fixtures/messages_doc.json +880 -0
- package/generated/versions/defold-1.12.4/gui.d.ts +43 -43
- package/generated/versions/defold-1.12.4/liveupdate.d.ts +22 -22
- package/generated/versions/defold-1.12.4/physics.d.ts +78 -75
- package/generated/versions/defold-1.12.4/render.d.ts +75 -55
- package/generated/versions/defold-1.12.4/resource.d.ts +187 -175
- package/generated/versions/defold-1.13.0/b2d.d.ts +33 -0
- package/generated/versions/defold-1.13.0/b2d_body.d.ts +676 -0
- package/generated/versions/defold-1.13.0/b2d_chain.d.ts +106 -0
- package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +155 -0
- package/generated/versions/defold-1.13.0/b2d_joint.d.ts +823 -0
- package/generated/versions/defold-1.13.0/b2d_shape.d.ts +215 -0
- package/generated/versions/defold-1.13.0/b2d_world.d.ts +314 -0
- package/generated/versions/defold-1.13.0/buffer.d.ts +176 -0
- package/generated/versions/defold-1.13.0/camera.d.ts +302 -0
- package/generated/versions/defold-1.13.0/collectionfactory.d.ts +146 -0
- package/generated/versions/defold-1.13.0/collectionproxy.d.ts +71 -0
- package/generated/versions/defold-1.13.0/compute.d.ts +306 -0
- package/generated/versions/defold-1.13.0/crash.d.ts +143 -0
- package/generated/versions/defold-1.13.0/editor-vm/http.d.ts +56 -0
- package/generated/versions/defold-1.13.0/editor-vm/json.d.ts +10 -0
- package/generated/versions/defold-1.13.0/editor-vm/localization.d.ts +42 -0
- package/generated/versions/defold-1.13.0/editor-vm/tilemap_tiles.d.ts +80 -0
- package/generated/versions/defold-1.13.0/editor-vm/zip.d.ts +10 -0
- package/generated/versions/defold-1.13.0/editor-vm/zlib.d.ts +24 -0
- package/generated/versions/defold-1.13.0/editor.d.ts +1092 -0
- package/generated/versions/defold-1.13.0/factory.d.ts +123 -0
- package/generated/versions/defold-1.13.0/font.d.ts +81 -0
- package/generated/versions/defold-1.13.0/go.d.ts +1054 -0
- package/generated/versions/defold-1.13.0/graphics.d.ts +321 -0
- package/generated/versions/defold-1.13.0/gui.d.ts +2370 -0
- package/generated/versions/defold-1.13.0/html5.d.ts +53 -0
- package/generated/versions/defold-1.13.0/http.d.ts +84 -0
- package/generated/versions/defold-1.13.0/iac.d.ts +18 -0
- package/generated/versions/defold-1.13.0/iap.d.ts +60 -0
- package/generated/versions/defold-1.13.0/image.d.ts +139 -0
- package/generated/versions/defold-1.13.0/index.d.ts +48 -0
- package/generated/versions/defold-1.13.0/json.d.ts +76 -0
- package/generated/versions/defold-1.13.0/kinds/editor-script.d.ts +13 -0
- package/generated/versions/defold-1.13.0/label.d.ts +94 -0
- package/generated/versions/defold-1.13.0/liveupdate.d.ts +140 -0
- package/generated/versions/defold-1.13.0/material.d.ts +444 -0
- package/generated/versions/defold-1.13.0/model.d.ts +246 -0
- package/generated/versions/defold-1.13.0/msg.d.ts +10 -0
- package/generated/versions/defold-1.13.0/particlefx.d.ts +166 -0
- package/generated/versions/defold-1.13.0/physics.d.ts +548 -0
- package/generated/versions/defold-1.13.0/profiler.d.ts +233 -0
- package/generated/versions/defold-1.13.0/push.d.ts +66 -0
- package/generated/versions/defold-1.13.0/render.d.ts +1185 -0
- package/generated/versions/defold-1.13.0/resource.d.ts +1530 -0
- package/generated/versions/defold-1.13.0/socket.d.ts +795 -0
- package/generated/versions/defold-1.13.0/sound.d.ts +291 -0
- package/generated/versions/defold-1.13.0/sprite.d.ts +157 -0
- package/generated/versions/defold-1.13.0/sys.d.ts +695 -0
- package/generated/versions/defold-1.13.0/tilemap.d.ts +195 -0
- package/generated/versions/defold-1.13.0/timer.d.ts +114 -0
- package/generated/versions/defold-1.13.0/types.d.ts +61 -0
- package/generated/versions/defold-1.13.0/vmath.d.ts +806 -0
- package/generated/versions/defold-1.13.0/webview.d.ts +68 -0
- package/generated/versions/defold-1.13.0/window.d.ts +198 -0
- package/generated/versions/defold-1.13.0/zlib.d.ts +40 -0
- package/index.d.ts +4 -84
- package/package.json +11 -3
- package/scripts/import-defold-release.ts +18 -1
- package/src/example-store.ts +5 -0
- package/scripts/lua-types-signature-index.ts +0 -151
|
@@ -0,0 +1,1984 @@
|
|
|
1
|
+
{
|
|
2
|
+
"b2d.body.create_chain": [
|
|
3
|
+
{
|
|
4
|
+
"sourceHash": "a4547c6be36805bc",
|
|
5
|
+
"ts": "const [chain, segments] = b2d.body.create_chain(body, {\n vertices: [vmath.vector3(-64, 0, 0), vmath.vector3(0, 16, 0), vmath.vector3(64, 0, 0)],\n prev_vertex: vmath.vector3(-96, 0, 0), next_vertex: vmath.vector3(96, 0, 0), friction: 0.6,\n});"
|
|
6
|
+
}
|
|
7
|
+
],
|
|
8
|
+
"b2d.body.create_fixture": [
|
|
9
|
+
{
|
|
10
|
+
"sourceHash": "1f1d588d084c0e48",
|
|
11
|
+
"ts": "const body = b2d.get_body(\"#collisionobject\");\nconst triangle = b2d.body.create_fixture(body, {\n density: 1.0, friction: 0.3,\n shape: { type: b2d.shape.SHAPE_TYPE_POLYGON, vertices: [vmath.vector3(-16, -16, 0), vmath.vector3(16, -16, 0), vmath.vector3(0, 16, 0)] },\n});"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"b2d.fixture.set_shape": [
|
|
15
|
+
{
|
|
16
|
+
"sourceHash": "ff836b80569f5d30",
|
|
17
|
+
"ts": "const body = b2d.get_body(\"#collisionobject\");\nconst circle = b2d.fixture.get_shape(body, 1);\ncircle.center = vmath.vector3(24, 0, 0);\nb2d.fixture.set_shape(body, 1, circle, true);\nb2d.fixture.set_shape(body, 2, { type: b2d.shape.SHAPE_TYPE_EDGE, v1: vmath.vector3(-32, 0, 0), v2: vmath.vector3(32, 0, 0) });"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"b2d.shape.set_shape": [
|
|
21
|
+
{
|
|
22
|
+
"sourceHash": "f31970e9ebb8d446",
|
|
23
|
+
"ts": "const body = b2d.get_body(\"#collisionobject\");\nconst circle = b2d.shape.get_shape(body, 1);\ncircle.center = vmath.vector3(24, 0, 0);\nb2d.shape.set_shape(body, 1, circle, true);\nb2d.shape.set_shape(body, 2, { type: b2d.shape.SHAPE_TYPE_SEGMENT, v1: vmath.vector3(-32, 0, 0), v2: vmath.vector3(32, 0, 0) });"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"buffer.copy_buffer": [
|
|
27
|
+
{
|
|
28
|
+
"sourceHash": "314e1246a630d761",
|
|
29
|
+
"ts": "// How to copy elements (e.g. vertices) from one buffer to another\n// copy entire buffer\nbuffer.copy_buffer(dstbuffer, 0, srcbuffer, 0, srcbuffer.length);\n\n// copy last 10 elements to the front of another buffer\nbuffer.copy_buffer(dstbuffer, 0, srcbuffer, srcbuffer.length - 10, 10);"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"buffer.copy_stream": [
|
|
33
|
+
{
|
|
34
|
+
"sourceHash": "359ea94639622db5",
|
|
35
|
+
"ts": "// How to update a texture of a sprite:\n// copy entire stream\nconst srcstream = buffer.get_stream(srcbuffer, hash(\"xyz\"));\nconst dststream = buffer.get_stream(dstbuffer, hash(\"xyz\"));\nbuffer.copy_stream(dststream, 0, srcstream, 0, srcstream.length);"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"buffer.create": [
|
|
39
|
+
{
|
|
40
|
+
"sourceHash": "d83315970921bbc7",
|
|
41
|
+
"ts": "// How to create and initialize a buffer\nexport default defineScript({\n init(self) {\n const size = 128;\n self.image = buffer.create(size * size, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n self.imagestream = buffer.get_stream(self.image, hash(\"rgb\"));\n\n for (let y = 0; y < self.height; y++) {\n for (let x = 0; x < self.width; x++) {\n const index = y * self.width * 3 + x * 3;\n self.imagestream[index + 0] = self.r;\n self.imagestream[index + 1] = self.g;\n self.imagestream[index + 2] = self.b;\n }\n }\n },\n});"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"buffer.get_metadata": [
|
|
45
|
+
{
|
|
46
|
+
"sourceHash": "fab020678d7483db",
|
|
47
|
+
"ts": "// How to get a metadata entry from a buffer\n// retrieve a metadata entry named \"somefloats\" and its numeric type\nconst [values, type] = buffer.get_metadata(buf, hash(\"somefloats\"));\nif (values) print(`${values.length} values in 'somefloats'`);"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"buffer.set_metadata": [
|
|
51
|
+
{
|
|
52
|
+
"sourceHash": "d2835d9dc456523a",
|
|
53
|
+
"ts": "// How to set a metadata entry on a buffer\n// create a new metadata entry with three floats\nbuffer.set_metadata(buf, hash(\"somefloats\"), [1.5, 3.2, 7.9], buffer.VALUE_TYPE_FLOAT32);\n// ...\n// update to a new set of values\nbuffer.set_metadata(buf, hash(\"somefloats\"), [-2.5, 10.0, 32.2], buffer.VALUE_TYPE_FLOAT32);"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"camera.get_cameras": [
|
|
57
|
+
{
|
|
58
|
+
"sourceHash": "d332d9320898b958",
|
|
59
|
+
"ts": "for (const camera_id of camera.get_cameras()) {\n render.set_camera(camera_id);\n render.draw(predicate);\n render.set_camera();\n}"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"camera.screen_to_world": [
|
|
63
|
+
{
|
|
64
|
+
"sourceHash": "0738c074908495cb",
|
|
65
|
+
"ts": "// Place objects at the touch point with a random Z position, keeping them\n// within the visible view zone.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed) {\n const perspective_camera = msg.url(\"#perspective_camera\");\n const random_z = math.random(\n camera.get_near_z(perspective_camera) + 0.01,\n camera.get_far_z(perspective_camera) - 0.01,\n );\n const world_position = camera.screen_to_world(\n vmath.vector3(action.screen_x, action.screen_y, random_z),\n perspective_camera,\n );\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"camera.screen_xy_to_world": [
|
|
69
|
+
{
|
|
70
|
+
"sourceHash": "ff65335713fc5698",
|
|
71
|
+
"ts": "// Place objects at the touch point.\nexport default defineScript({\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\")) {\n if (action.pressed) {\n const world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y);\n go.set_position(world_position, \"/go1\");\n }\n }\n },\n});"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"camera.world_to_screen": [
|
|
75
|
+
{
|
|
76
|
+
"sourceHash": "6b6fd9030f4591e2",
|
|
77
|
+
"ts": "// Convert a game object position into a screen position.\ngo.update_world_transform(\"/go1\");\nconst world_pos = go.get_world_position(\"/go1\");\nconst screen_pos = camera.world_to_screen(world_pos);"
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"collectionfactory.create": [
|
|
81
|
+
{
|
|
82
|
+
"sourceHash": "5a49721288808772",
|
|
83
|
+
"ts": "// How to spawn a collection of game objects:\nexport default defineScript({\n init(self) {\n // Spawn a small group of enemies.\n const pos = vmath.vector3(100, 12.5, 0);\n const rot = vmath.quat_rotation_z(Math.PI / 2);\n const scale = 0.5;\n const props = {\n [hash(\"/enemy_leader\")]: { health: 1000.0 },\n [hash(\"/enemy_1\")]: { health: 200.0 },\n [hash(\"/enemy_2\")]: { health: 400.0, color: hash(\"green\") },\n };\n\n self.enemy_ids = collectionfactory.create(\"#enemyfactory\", pos, rot, props, scale);\n // enemy_ids now map to the spawned instance ids:\n //\n // pprint(self.enemy_ids)\n //\n // DEBUG:SCRIPT:\n // {\n // hash: [/enemy_leader] = hash: [/collection0/enemy_leader],\n // hash: [/enemy_1] = hash: [/collection0/enemy_1],\n // hash: [/enemy_2] = hash: [/collection0/enemy_2]\n // }\n\n // Send \"attack\" message to the leader. First look up its instance id.\n const leader_id = self.enemy_ids[hash(\"/enemy_leader\")];\n msg.post(leader_id, \"attack\");\n },\n});\n\n// How to delete a spawned collection:\ngo.delete(self.enemy_ids);"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"collectionfactory.load": [
|
|
87
|
+
{
|
|
88
|
+
"sourceHash": "777c98a389da34db",
|
|
89
|
+
"ts": "// How to load resources of a collection factory prototype.\ncollectionfactory.load(\"#factory\", (self, url, result) => {});"
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"collectionfactory.set_prototype": [
|
|
93
|
+
{
|
|
94
|
+
"sourceHash": "53a6c8f3903b8f4a",
|
|
95
|
+
"ts": "// How to unload the previous prototype's resources, and then spawn a new collection:\ncollectionfactory.unload(\"#factory\"); // unload the previous resources\ncollectionfactory.set_prototype(\"#factory\", \"/main/levels/level1.collectionc\");\nconst ids = collectionfactory.create(\"#factory\", go.get_world_position(), vmath.quat());"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"collectionfactory.unload": [
|
|
99
|
+
{
|
|
100
|
+
"sourceHash": "b1bfded6b48571a6",
|
|
101
|
+
"ts": "// How to unload resources of a collection factory prototype loaded with collectionfactory.load:\ncollectionfactory.unload(\"#factory\");"
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"collectionproxy.get_resources": [
|
|
105
|
+
{
|
|
106
|
+
"sourceHash": "5bba0e0917a2a842",
|
|
107
|
+
"ts": "function print_resources(self, cproxy) {\n const resources = collectionproxy.get_resources(cproxy);\n for (const v of resources) {\n print(`Resource: ${v}`);\n }\n}"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"collectionproxy.load": [
|
|
111
|
+
{
|
|
112
|
+
"sourceHash": "7f38a3119be56e98",
|
|
113
|
+
"ts": "collectionproxy.load(\"#proxy\", undefined, (self, message_id, message, sender) => {\n if (message_id === hash(\"proxy_ready\")) {\n print(\"proxy is ready\");\n } else if (message_id === hash(\"proxy_loading\")) {\n print(\"progress\", message.progress);\n } else if (message_id === hash(\"proxy_error\")) {\n print(\"error\", message.code);\n }\n});"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"collectionproxy.set_collection": [
|
|
117
|
+
{
|
|
118
|
+
"sourceHash": "baa612ded17474d3",
|
|
119
|
+
"ts": "// The example assumes the script belongs to an instance with a\n// collection-proxy-component with id \"proxy\".\nconst [ok, error] = collectionproxy.set_collection(\"/go#collectionproxy\", \"/LU/3.collectionc\");\nif (ok) {\n print(\"The collection has been changed to /LU/3.collectionc\");\n} else {\n print(\"Error changing collection to /LU/3.collectionc \", error);\n}\nmsg.post(\"/go#collectionproxy\", \"load\");\nmsg.post(\"/go#collectionproxy\", \"init\");\nmsg.post(\"/go#collectionproxy\", \"enable\");"
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
"compute.get_constants": [
|
|
123
|
+
{
|
|
124
|
+
"sourceHash": "2e280ba4897a3652",
|
|
125
|
+
"ts": "const constants = compute.get_constants(\"/my_compute.computec\");"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"compute.get_samplers": [
|
|
129
|
+
{
|
|
130
|
+
"sourceHash": "24d497581f91ce76",
|
|
131
|
+
"ts": "const samplers = compute.get_samplers(\"/my_compute.computec\");"
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"compute.get_textures": [
|
|
135
|
+
{
|
|
136
|
+
"sourceHash": "ea1db550a8f2dc8c",
|
|
137
|
+
"ts": "const textures = compute.get_textures(\"/my_compute.computec\");"
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
"compute.set_constants": [
|
|
141
|
+
{
|
|
142
|
+
"sourceHash": "e14e2048f75cadc6",
|
|
143
|
+
"ts": "compute.set_constants(\"/my_compute.computec\", { tint: { value: vmath.vector4(1, 0, 0, 1) } });"
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"compute.set_samplers": [
|
|
147
|
+
{
|
|
148
|
+
"sourceHash": "51ac79099b9605ba",
|
|
149
|
+
"ts": "compute.set_samplers(\"/my_compute.computec\", { texture_sampler: { u_wrap: graphics.TEXTURE_WRAP_REPEAT, v_wrap: graphics.TEXTURE_WRAP_MIRRORED_REPEAT } });"
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"compute.set_textures": [
|
|
153
|
+
{
|
|
154
|
+
"sourceHash": "87edc357f8852364",
|
|
155
|
+
"ts": "compute.set_textures(\"/my_compute.computec\", { my_texture: resource.texture() });"
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
"editor.bob": [
|
|
159
|
+
{
|
|
160
|
+
"sourceHash": "3d4699538f2b8207",
|
|
161
|
+
"ts": "// Print help in the console:\neditor.bob({ help: true });\n\n// Bundle the game for the host platform:\nconst opts = { archive: true, platform: editor.platform };\neditor.bob(opts, \"distclean\", \"resolve\", \"build\", \"bundle\");\n\n// Using snake_cased and repeated options:\nconst bundleOpts = {\n archive: true,\n platform: editor.platform,\n build_server: \"https://build.my-company.com\",\n settings: [\"test.ini\", \"headless.ini\"],\n};\neditor.bob(bundleOpts, \"distclean\", \"resolve\", \"build\");"
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
"editor.command": [
|
|
165
|
+
{
|
|
166
|
+
"sourceHash": "41caebab7bdd6774",
|
|
167
|
+
"ts": "// Print Git history for a file:\neditor.command({\n label: \"Git History\",\n query: { selection: { type: \"resource\", cardinality: \"one\" } },\n run: (opts) => {\n editor.execute(\"git\", \"log\", \"--follow\", `.${editor.get(opts.selection, \"path\")}`, {\n reload_resources: false,\n });\n },\n});"
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
"editor.create_directory": [
|
|
171
|
+
{
|
|
172
|
+
"sourceHash": "0a8ce244797b5428",
|
|
173
|
+
"ts": "editor.create_directory(\"/assets/gen\");"
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"editor.create_resources": [
|
|
177
|
+
{
|
|
178
|
+
"sourceHash": "b650f0d98eccb0fd",
|
|
179
|
+
"ts": "// Create a single resource from template:\neditor.create_resources([\"/npc.go\"]);\n\n// Create multiple resources:\neditor.create_resources([\"/npc.go\", \"/levels/1.collection\", \"/levels/2.collection\"]);\n\n// Create a resource with custom content:\neditor.create_resources([[\"/npc.script\", \"go.property('hp', 100)\"]]);"
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
"editor.delete_directory": [
|
|
183
|
+
{
|
|
184
|
+
"sourceHash": "48be8868842c3e45",
|
|
185
|
+
"ts": "editor.delete_directory(\"/assets/gen\");"
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"editor.execute": [
|
|
189
|
+
{
|
|
190
|
+
"sourceHash": "b22ea40a2a3595b2",
|
|
191
|
+
"ts": "// Make a directory with spaces in it:\neditor.execute(\"mkdir\", \"new dir\");\n\n// Read the git status:\nconst status = editor.execute(\"git\", \"status\", \"--porcelain\", {\n reload_resources: false,\n out: \"capture\",\n});"
|
|
192
|
+
}
|
|
193
|
+
],
|
|
194
|
+
"editor.ui.use_memo": [
|
|
195
|
+
{
|
|
196
|
+
"sourceHash": "dac97ede337c4f69",
|
|
197
|
+
"ts": "function increment(n: unknown): number {\n return (n as number) + 1;\n}\n\nfunction makeListener(setCount: unknown) {\n return () => {\n (setCount as (update: unknown) => unknown)(increment);\n };\n}\n\nconst counterButton = editor.ui.component((props) => {\n const [count, setCount] = editor.ui.use_state((props as { count: unknown }).count);\n const onPressed = editor.ui.use_memo(makeListener, setCount);\n return editor.ui.button({\n text: tostring(count),\n on_pressed: onPressed,\n });\n});"
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
"editor.ui.use_state": [
|
|
201
|
+
{
|
|
202
|
+
"sourceHash": "3065b49232e1a2de",
|
|
203
|
+
"ts": "function increment(n: unknown): number {\n return (n as number) + 1;\n}\n\nconst counterButton = editor.ui.component((props) => {\n const [count, setCount] = editor.ui.use_state((props as { count: unknown }).count);\n return editor.ui.button({\n text: tostring(count),\n on_pressed: () => {\n setCount(increment);\n },\n });\n});"
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
"factory.create": [
|
|
207
|
+
{
|
|
208
|
+
"sourceHash": "d2cd2037a9127ec6",
|
|
209
|
+
"ts": "// How to create a new game object:\nexport default defineScript({\n init(self) {\n // create a new game object and provide property values\n self.my_created_object = factory.create(\"#factory\", undefined, undefined, { my_value: 1 });\n // communicate with the object\n msg.post(self.my_created_object, \"hello\");\n },\n});\n\n// And then let the new game object have a script attached:\ngo.property(\"my_value\", 0);\n\nexport default defineScript({\n init(self) {\n // do something with self.my_value which is now one\n },\n});"
|
|
210
|
+
}
|
|
211
|
+
],
|
|
212
|
+
"factory.load": [
|
|
213
|
+
{
|
|
214
|
+
"sourceHash": "64dff473cc2b3abd",
|
|
215
|
+
"ts": "// How to load resources of a factory prototype.\nfactory.load(\"#factory\", (self, url, result) => {});"
|
|
216
|
+
}
|
|
217
|
+
],
|
|
218
|
+
"factory.set_prototype": [
|
|
219
|
+
{
|
|
220
|
+
"sourceHash": "e0d61d4f234d1bdc",
|
|
221
|
+
"ts": "// How to unload the previous prototype's resources, and then spawn a new game object:\nfactory.unload(\"#factory\"); // unload the previous resources\nfactory.set_prototype(\"#factory\", \"/main/levels/enemyA.goc\");\nconst id = factory.create(\"#factory\", go.get_world_position(), vmath.quat());"
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
"factory.unload": [
|
|
225
|
+
{
|
|
226
|
+
"sourceHash": "260bb70c2be6171a",
|
|
227
|
+
"ts": "// How to unload resources of a factory prototype loaded with factory.load:\nfactory.unload(\"#factory\");"
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
"final": [
|
|
231
|
+
{
|
|
232
|
+
"sourceHash": "ebc3cae218af001a",
|
|
233
|
+
"ts": "export default defineScript({\n final(self) {\n // report finalization\n msg.post(\"my_friend_instance\", \"im_dead\", { my_stats: self.some_value });\n },\n});"
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
"font.add_font": [
|
|
237
|
+
{
|
|
238
|
+
"sourceHash": "eb23e196a4edbd74",
|
|
239
|
+
"ts": "const font_hash = hash(\"/assets/fonts/roboto.fontc\");\nconst ttf_hash = hash(\"/assets/fonts/Roboto/Roboto-Bold.ttf\");\nfont.add_font(font_hash, ttf_hash);"
|
|
240
|
+
}
|
|
241
|
+
],
|
|
242
|
+
"font.prewarm_text": [
|
|
243
|
+
{
|
|
244
|
+
"sourceHash": "f16bb17432638957",
|
|
245
|
+
"ts": "const font_hash = hash(\"/assets/fonts/roboto.fontc\");\nfont.prewarm_text(font_hash, \"Some text\", (self, request_id, result, errstring) => {\n // cache is warm, show the text!\n});"
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
"font.remove_font": [
|
|
249
|
+
{
|
|
250
|
+
"sourceHash": "a3686e94e8a0a9d5",
|
|
251
|
+
"ts": "const font_hash = hash(\"/assets/fonts/roboto.fontc\");\nconst ttf_hash = hash(\"/assets/fonts/Roboto/Roboto-Bold.ttf\");\nfont.remove_font(font_hash, ttf_hash);"
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
"go.animate": [
|
|
255
|
+
{
|
|
256
|
+
"sourceHash": "ec6a31d150125e06",
|
|
257
|
+
"ts": "// Animate the position of a game object to x = 10 during 1 second, then\n// y = 20 during 1 second:\ngo.animate(go.get_id(), \"position.x\", go.PLAYBACK_ONCE_FORWARD, 10, go.EASING_LINEAR, 1, 0, () => {\n go.animate(go.get_id(), \"position.y\", go.PLAYBACK_ONCE_FORWARD, 20, go.EASING_LINEAR, 1);\n});\n\n// Animate the y position of a game object using a crazy custom easing curve:\nconst values = [\n 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,\n 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,\n 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,\n 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,\n];\nconst vec = vmath.vector(values);\ngo.animate(\"go\", \"position.y\", go.PLAYBACK_LOOP_PINGPONG, 100, vec, 2.0);"
|
|
258
|
+
}
|
|
259
|
+
],
|
|
260
|
+
"go.cancel_animations": [
|
|
261
|
+
{
|
|
262
|
+
"sourceHash": "4f012d6eb3d73ce9",
|
|
263
|
+
"ts": "// Cancel the animation of the position of a game object:\ngo.cancel_animations(go.get_id(), \"position\");\n\n// Cancel all property animations of the current game object:\ngo.cancel_animations(\".\");\n\n// Cancel all property animations of the sprite component of the current game object:\ngo.cancel_animations(\"#sprite\");"
|
|
264
|
+
}
|
|
265
|
+
],
|
|
266
|
+
"go.delete": [
|
|
267
|
+
{
|
|
268
|
+
"sourceHash": "63517a8a15d5d030",
|
|
269
|
+
"ts": "// This example demonstrates how to delete game objects:\n// Delete the script's own game object.\ngo.delete();\n// Delete a game object with the id \"my_game_object\".\nconst id = go.get_id(\"my_game_object\");\ngo.delete(id);\n// Delete a list of game objects.\nconst ids = [hash(\"/my_object_1\"), hash(\"/my_object_2\"), hash(\"/my_object_3\")];\ngo.delete(ids);\n\n// This example demonstrates how to delete game objects and their children\n// (child-to-parent order):\n// Delete the script's own game object and its children.\ngo.delete(true);\n// Delete a game object with the id \"my_game_object\" and its children.\nconst id2 = go.get_id(\"my_game_object\");\ngo.delete(id2, true);\n// Delete a list of game objects and their children.\nconst ids2 = [hash(\"/my_object_1\"), hash(\"/my_object_2\"), hash(\"/my_object_3\")];\ngo.delete(ids2, true);"
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
"go.exists": [
|
|
273
|
+
{
|
|
274
|
+
"sourceHash": "377b4eb5d71df398",
|
|
275
|
+
"ts": "// Check if game object \"my_game_object\" exists in the current collection:\ngo.exists(\"/my_game_object\");\n\n// Check if game object exists in another collection:\ngo.exists(\"other_collection:/my_game_object\");"
|
|
276
|
+
}
|
|
277
|
+
],
|
|
278
|
+
"go.get": [
|
|
279
|
+
{
|
|
280
|
+
"sourceHash": "7cac2203eda50a5e",
|
|
281
|
+
"ts": "// Get a property \"speed\" from a script \"player\"; the property must be declared\n// in the player script:\ngo.property(\"speed\", 50);\n\n// Then in the calling script (assumed to belong to the same game object, but it\n// does not have to):\nconst speed = go.get(\"#player\", \"speed\");\n\n// Get a value in a material property array (the glsl indices are 0-based):\ngo.get(url, \"example\", { index: 1 }); // the first vector4 in the array: example[0]\ngo.get(url, \"example\", { index: 16 }); // the last vector4 in the array: example[15]\ngo.get(url, \"example.x\", { index: 1 }); // an element of a vector4: example[0].x\n\n// Get all values in a material property array as a table:\ngo.get(url, \"example\"); // => [vector4, vector4, ...]\ngo.get(url, \"example.x\"); // => [number1, number2, ...]\n\n// Get a named property (the resource of a certain gui font):\nconst font_hash = go.get(\"#gui\", \"fonts\", { key: \"system_font_BIG\" });\n\n// Get a property from a sub-component, using the \"keys\" options table\n// (addressing the first level of a component):\ngo.get(\"#particlefx\", \"material\", { keys: [\"cone_emitter\"] });\n\n// Get a property in a deeper sub-hierarchy (if the component supports it).\n// Note: no built-in component supports this yet, but a custom one could.\ngo.get(\"#my_component\", \"some_property\", { keys: [\"root\", \"child_node\"] });"
|
|
282
|
+
}
|
|
283
|
+
],
|
|
284
|
+
"go.get_id": [
|
|
285
|
+
{
|
|
286
|
+
"sourceHash": "74e9ff5ee9521c51",
|
|
287
|
+
"ts": "// For the instance with path /my_sub_collection/my_instance, the following calls\n// are equivalent:\nconst id = go.get_id(); // no path, defaults to the instance containing the calling script\nprint(id); // => hash: [/my_sub_collection/my_instance]\n\nconst id2 = go.get_id(\"/my_sub_collection/my_instance\"); // absolute path\nprint(id2); // => hash: [/my_sub_collection/my_instance]\n\nconst id3 = go.get_id(\"my_instance\"); // relative path\nprint(id3); // => hash: [/my_sub_collection/my_instance]"
|
|
288
|
+
}
|
|
289
|
+
],
|
|
290
|
+
"go.get_parent": [
|
|
291
|
+
{
|
|
292
|
+
"sourceHash": "6e98305fd4cd8f14",
|
|
293
|
+
"ts": "// Get parent of the instance containing the calling script:\nconst parent_id = go.get_parent();\n\n// Get parent of the instance with id \"x\":\nconst parent_id2 = go.get_parent(\"x\");"
|
|
294
|
+
}
|
|
295
|
+
],
|
|
296
|
+
"go.get_position": [
|
|
297
|
+
{
|
|
298
|
+
"sourceHash": "958a14823ca50504",
|
|
299
|
+
"ts": "// Get the position of the game object the script is attached to:\nconst p = go.get_position();\n\n// Get the position of another game object \"my_gameobject\":\nconst pos = go.get_position(\"my_gameobject\");"
|
|
300
|
+
}
|
|
301
|
+
],
|
|
302
|
+
"go.get_rotation": [
|
|
303
|
+
{
|
|
304
|
+
"sourceHash": "46e4f7ff790322c3",
|
|
305
|
+
"ts": "// Get the rotation of the game object the script is attached to:\nconst r = go.get_rotation();\n\n// Get the rotation of another game object with id \"x\":\nconst r2 = go.get_rotation(\"x\");"
|
|
306
|
+
}
|
|
307
|
+
],
|
|
308
|
+
"go.get_scale": [
|
|
309
|
+
{
|
|
310
|
+
"sourceHash": "b6a9bd9d19741cdd",
|
|
311
|
+
"ts": "// Get the scale of the game object the script is attached to:\nconst s = go.get_scale();\n\n// Get the scale of another game object with id \"x\":\nconst s2 = go.get_scale(\"x\");"
|
|
312
|
+
}
|
|
313
|
+
],
|
|
314
|
+
"go.get_scale_uniform": [
|
|
315
|
+
{
|
|
316
|
+
"sourceHash": "0add83a46d3434c3",
|
|
317
|
+
"ts": "// Get the uniform scale of the game object the script is attached to:\nconst s = go.get_scale_uniform();\n\n// Get the uniform scale of another game object with id \"x\":\nconst s2 = go.get_scale_uniform(\"x\");"
|
|
318
|
+
}
|
|
319
|
+
],
|
|
320
|
+
"go.get_world_position": [
|
|
321
|
+
{
|
|
322
|
+
"sourceHash": "ab804a5cdcfd4f7d",
|
|
323
|
+
"ts": "// Get the world position of the game object the script is attached to:\nconst p = go.get_world_position();\n\n// Reach a sibling game object by its id \u2014 relative addressing, no socket prefix:\nconst p2 = go.get_world_position(\"x\");"
|
|
324
|
+
}
|
|
325
|
+
],
|
|
326
|
+
"go.get_world_rotation": [
|
|
327
|
+
{
|
|
328
|
+
"sourceHash": "05c7e59676f614f9",
|
|
329
|
+
"ts": "// Get the world rotation of the game object the script is attached to:\nconst r = go.get_world_rotation();\n\n// Get the world rotation of another game object with id \"x\":\nconst r2 = go.get_world_rotation(\"x\");"
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
"go.get_world_scale": [
|
|
333
|
+
{
|
|
334
|
+
"sourceHash": "bbbe0d3b0c6a9153",
|
|
335
|
+
"ts": "// Get the world 3D scale of the game object the script is attached to:\nconst s = go.get_world_scale();\n\n// Get the world scale of another game object \"x\":\nconst s2 = go.get_world_scale(\"x\");"
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
"go.get_world_scale_uniform": [
|
|
339
|
+
{
|
|
340
|
+
"sourceHash": "14162dd238db34dd",
|
|
341
|
+
"ts": "// Get the world uniform scale of the game object the script is attached to:\nconst s = go.get_world_scale_uniform();\n\n// Get the world uniform scale of another game object with id \"x\":\nconst s2 = go.get_world_scale_uniform(\"x\");"
|
|
342
|
+
}
|
|
343
|
+
],
|
|
344
|
+
"go.get_world_transform": [
|
|
345
|
+
{
|
|
346
|
+
"sourceHash": "832de2e98a73e953",
|
|
347
|
+
"ts": "// Get the world transform of the game object the script is attached to:\nconst m = go.get_world_transform();\n\n// Get the world transform of another game object with id \"x\":\nconst m2 = go.get_world_transform(\"x\");"
|
|
348
|
+
}
|
|
349
|
+
],
|
|
350
|
+
"go.property": [
|
|
351
|
+
{
|
|
352
|
+
"sourceHash": "96e6079cda36fa54",
|
|
353
|
+
"ts": "// This example defines a property \"health\" in a script. The health is decreased\n// whenever someone sends a \"take_damage\" message to the script.\ngo.property(\"health\", 100);\n\nexport default defineScript({\n init(self) {\n // prints 100 to the output\n print(self.health);\n },\n\n on_message(self, message_id, message) {\n if (message_id === hash(\"take_damage\")) {\n self.health = self.health - message.damage;\n print(`Ouch! My health is now: ${self.health}`);\n }\n },\n});"
|
|
354
|
+
}
|
|
355
|
+
],
|
|
356
|
+
"go.set": [
|
|
357
|
+
{
|
|
358
|
+
"sourceHash": "2ca1763ad71c1232",
|
|
359
|
+
"ts": "// Set a property \"speed\" of a script \"player\"; the property must be declared in\n// the player script:\ngo.property(\"speed\", 50);\n\n// Then in the calling script (assumed to belong to the same game object, but it\n// does not have to):\ngo.set(\"#player\", \"speed\", 100);\n\n// Set a vector4 in a material property array (the glsl indices are 0-based):\ngo.set(url, \"example\", vmath.vector4(1, 1, 1, 1), { index: 1 }); // example[0] = v\ngo.set(url, \"example\", vmath.vector4(2, 2, 2, 2), { index: 16 }); // example[15] = v\ngo.set(url, \"example.x\", 7, { index: 1 }); // example[0].x = 7\n\n// Set a material property array by a table of vector4 (only the first two are\n// set; extra array elements are ignored):\ngo.set(url, \"example\", [vmath.vector4(1, 1, 1, 1), vmath.vector4(2, 2, 2, 2)]);\n\n// Set a named property (inside init(self)):\ngo.property(\"big_font\", resource.font());\ngo.set(\"#gui\", \"fonts\", self.big_font, { key: \"system_font_BIG\" });\n\n// Set a property on a sub-component, using the \"keys\" options table (inside\n// init(self)):\ngo.property(\"my_material\", resource.material);\ngo.set(\"#particlefx\", \"material\", self.my_material, { keys: [\"cone_emitter\"] });\n\n// Set a property in a deeper sub-hierarchy (if the component supports it).\n// Note: no built-in component supports this yet, but a custom one could.\ngo.set(\"#my_component\", \"some_property\", some_value, { keys: [\"root\", \"child_node\"] });"
|
|
360
|
+
}
|
|
361
|
+
],
|
|
362
|
+
"go.set_parent": [
|
|
363
|
+
{
|
|
364
|
+
"sourceHash": "2822e1839ed2a321",
|
|
365
|
+
"ts": "// Attach myself to another instance \"my_parent\":\ngo.set_parent(go.get_id(), go.get_id(\"my_parent\"));\n\n// Attach an instance \"my_instance\" to another instance \"my_parent\":\ngo.set_parent(go.get_id(\"my_instance\"), go.get_id(\"my_parent\"));\n\n// Detach an instance \"my_instance\" from its parent (if any):\ngo.set_parent(go.get_id(\"my_instance\"));"
|
|
366
|
+
}
|
|
367
|
+
],
|
|
368
|
+
"go.set_position": [
|
|
369
|
+
{
|
|
370
|
+
"sourceHash": "ad83d0274d776e8f",
|
|
371
|
+
"ts": "// `p` is the desired position (a Vector3).\nconst p = vmath.vector3();\n\n// Set the position of the game object the script is attached to:\ngo.set_position(p);\n\n// Reach a sibling game object by its id \u2014 relative addressing, no socket prefix:\ngo.set_position(p, \"x\");"
|
|
372
|
+
}
|
|
373
|
+
],
|
|
374
|
+
"go.set_rotation": [
|
|
375
|
+
{
|
|
376
|
+
"sourceHash": "782b2092fc7f641f",
|
|
377
|
+
"ts": "// `r` is the desired rotation (a Quaternion).\nconst r = vmath.quat();\n\n// Set the rotation of the game object the script is attached to:\ngo.set_rotation(r);\n\n// Set the rotation of another game object with id \"x\":\ngo.set_rotation(r, \"x\");"
|
|
378
|
+
}
|
|
379
|
+
],
|
|
380
|
+
"go.set_scale": [
|
|
381
|
+
{
|
|
382
|
+
"sourceHash": "456df524622a534f",
|
|
383
|
+
"ts": "// Set the scale of the game object the script is attached to:\nconst s = vmath.vector3(2.0, 1.0, 1.0);\ngo.set_scale(s);\n\n// Set the scale of another game object with id \"obj_id\":\nconst s2 = 1.2;\ngo.set_scale(s2, \"obj_id\");"
|
|
384
|
+
}
|
|
385
|
+
],
|
|
386
|
+
"go.set_scale_xy": [
|
|
387
|
+
{
|
|
388
|
+
"sourceHash": "6d23b1a65292cf1f",
|
|
389
|
+
"ts": "// Set the scale of the game object the script is attached to:\nconst s = vmath.vector3(2.0, 1.0, 5.0);\ngo.set_scale_xy(s); // z will not be set here, only x and y\n\n// Set the scale of another game object with id \"obj_id\":\nconst s2 = 1.2;\ngo.set_scale_xy(s2, \"obj_id\"); // z will not be set here, only x and y"
|
|
390
|
+
}
|
|
391
|
+
],
|
|
392
|
+
"go.update_world_transform": [
|
|
393
|
+
{
|
|
394
|
+
"sourceHash": "0c189fdea4a6d715",
|
|
395
|
+
"ts": "// Update this game object's world transform:\ngo.update_world_transform();\n\n// Update another game object's world transform:\ngo.update_world_transform(\"/other\");"
|
|
396
|
+
}
|
|
397
|
+
],
|
|
398
|
+
"go.world_to_local_position": [
|
|
399
|
+
{
|
|
400
|
+
"sourceHash": "29852f7285321a3e",
|
|
401
|
+
"ts": "// Convert position of \"test\" game object into coordinate space of \"child\" object.\nconst test_pos = go.get_world_position(\"/test\");\nconst child_pos = go.get_world_position(\"/child\");\nconst new_position = go.world_to_local_position(test_pos, \"/child\");"
|
|
402
|
+
}
|
|
403
|
+
],
|
|
404
|
+
"go.world_to_local_transform": [
|
|
405
|
+
{
|
|
406
|
+
"sourceHash": "b9df312459adbb0f",
|
|
407
|
+
"ts": "// Convert transform of \"test\" game object into coordinate space of \"child\" object.\nconst test_transform = go.get_world_transform(\"/test\");\nconst child_transform = go.get_world_transform(\"/child\");\nconst result_transform = go.world_to_local_transform(test_transform, \"/child\");"
|
|
408
|
+
}
|
|
409
|
+
],
|
|
410
|
+
"gui.animate": [
|
|
411
|
+
{
|
|
412
|
+
"sourceHash": "afd63fafe7e65e70",
|
|
413
|
+
"ts": "// How to start a simple color animation, where the node fades in to white during 0.5 seconds:\ngui.set_color(node, vmath.vector4(0, 0, 0, 0)); // node is fully transparent\ngui.animate(node, gui.PROP_COLOR, vmath.vector4(1, 1, 1, 1), gui.EASING_INOUTQUAD, 0.5); // start animation\n\n// How to start a sequenced animation where the node fades in to white during 0.5\n// seconds, stays visible for 2 seconds and then fades out:\nfunction on_animation_done(self, node) {\n // fade out node, but wait 2 seconds before the animation starts\n gui.animate(node, gui.PROP_COLOR, vmath.vector4(0, 0, 0, 0), gui.EASING_OUTQUAD, 0.5, 2.0);\n}\n\nexport default defineScript({\n init(self) {\n // fetch the node we want to animate\n const my_node = gui.get_node(\"my_node\");\n // node is initially set to fully transparent\n gui.set_color(my_node, vmath.vector4(0, 0, 0, 0));\n // animate the node immediately and call on_animation_done when the animation has completed\n gui.animate(my_node, gui.PROP_COLOR, vmath.vector4(1, 1, 1, 1), gui.EASING_INOUTQUAD, 0.5, 0.0, on_animation_done);\n },\n});\n\n// How to animate a node's y position using a crazy custom easing curve:\nexport default defineScript({\n init(self) {\n const values = [\n 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,\n 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,\n 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,\n 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,\n ];\n const vec = vmath.vector(values);\n const node = gui.get_node(\"box\");\n gui.animate(node, \"position.y\", 100, vec, 4.0, 0, undefined, gui.PLAYBACK_LOOP_PINGPONG);\n },\n});"
|
|
414
|
+
}
|
|
415
|
+
],
|
|
416
|
+
"gui.cancel_animations": [
|
|
417
|
+
{
|
|
418
|
+
"sourceHash": "ac678b79b816b54d",
|
|
419
|
+
"ts": "// Start an animation of the position property of a node, then cancel parts of\n// the animation:\nconst node = gui.get_node(\"my_node\");\n// animate to new position\nconst pos = vmath.vector3(100, 100, 0);\ngui.animate(node, \"position\", pos, go.EASING_LINEAR, 2);\n// ...\n// cancel animation of the x component.\ngui.cancel_animations(node, \"position.x\");\n\n// Cancels all property animations on a node in a single call:\n// animate to new position and scale\ngui.animate(node, \"position\", vmath.vector3(100, 100, 0), go.EASING_LINEAR, 5);\ngui.animate(node, \"scale\", vmath.vector3(0.5), go.EASING_LINEAR, 5);\n// ...\n// cancel positioning and scaling at once\ngui.cancel_animations(node);"
|
|
420
|
+
}
|
|
421
|
+
],
|
|
422
|
+
"gui.cancel_flipbook": [
|
|
423
|
+
{
|
|
424
|
+
"sourceHash": "7fe129302536559d",
|
|
425
|
+
"ts": "const node = gui.get_node(\"anim_node\");\ngui.cancel_flipbook(node);"
|
|
426
|
+
}
|
|
427
|
+
],
|
|
428
|
+
"gui.delete_node": [
|
|
429
|
+
{
|
|
430
|
+
"sourceHash": "5c7d72924a7c046c",
|
|
431
|
+
"ts": "// Delete a particular node and any child nodes it might have:\nconst node = gui.get_node(\"my_node\");\ngui.delete_node(node);"
|
|
432
|
+
}
|
|
433
|
+
],
|
|
434
|
+
"gui.delete_texture": [
|
|
435
|
+
{
|
|
436
|
+
"sourceHash": "360a3c74413c6a02",
|
|
437
|
+
"ts": "export default defineScript({\n init(self) {\n // Create a texture.\n if (gui.new_texture(\"temp_tx\", 10, 10, \"rgb\", \"\\0\".repeat(10 * 10 * 3))) {\n // Do something with the texture.\n // ...\n\n // Delete the texture\n gui.delete_texture(\"temp_tx\");\n }\n },\n});"
|
|
438
|
+
}
|
|
439
|
+
],
|
|
440
|
+
"gui.get": [
|
|
441
|
+
{
|
|
442
|
+
"sourceHash": "7537f46e06a28364",
|
|
443
|
+
"ts": "// Get properties on existing nodes:\nconst node = gui.get_node(\"my_box_node\");\nconst node_position = gui.get(node, \"position\");"
|
|
444
|
+
}
|
|
445
|
+
],
|
|
446
|
+
"gui.get_font_resource": [
|
|
447
|
+
{
|
|
448
|
+
"sourceHash": "8eda6241dbbefbbb",
|
|
449
|
+
"ts": "// Get the text metrics for a text\nexport default defineScript({\n init(self) {\n const node = gui.get_node(\"name\");\n const font_name = gui.get_font(node);\n const font = gui.get_font_resource(font_name);\n const metrics = resource.get_text_metrics(font, \"The quick brown fox\\n jumps over the lazy dog\");\n },\n});"
|
|
450
|
+
}
|
|
451
|
+
],
|
|
452
|
+
"gui.get_id": [
|
|
453
|
+
{
|
|
454
|
+
"sourceHash": "d0f66014d2dc71cf",
|
|
455
|
+
"ts": "// Gets the id of a node:\nconst node = gui.get_node(\"my_node\");\n\nconst id = gui.get_id(node);\nprint(id); // => hash: [my_node]"
|
|
456
|
+
}
|
|
457
|
+
],
|
|
458
|
+
"gui.get_index": [
|
|
459
|
+
{
|
|
460
|
+
"sourceHash": "fb2945b610c767ee",
|
|
461
|
+
"ts": "// Compare the index order of two sibling nodes:\nconst node1 = gui.get_node(\"my_node_1\");\nconst node2 = gui.get_node(\"my_node_2\");\n\nif (gui.get_index(node1) < gui.get_index(node2)) {\n // node1 is drawn below node2\n} else {\n // node2 is drawn below node1\n}"
|
|
462
|
+
}
|
|
463
|
+
],
|
|
464
|
+
"gui.get_material": [
|
|
465
|
+
{
|
|
466
|
+
"sourceHash": "d7e366c5ee012f40",
|
|
467
|
+
"ts": "// Getting the material for a node, and assign it to another node:\nconst node1 = gui.get_node(\"my_node\");\nconst node2 = gui.get_node(\"other_node\");\nconst node1_material = gui.get_material(node1);\ngui.set_material(node2, node1_material);"
|
|
468
|
+
}
|
|
469
|
+
],
|
|
470
|
+
"gui.get_node": [
|
|
471
|
+
{
|
|
472
|
+
"sourceHash": "c7c9fde72585b0bf",
|
|
473
|
+
"ts": "// Gets a node by id and change its color:\nconst node = gui.get_node(\"my_node\");\nconst red = vmath.vector4(1.0, 0.0, 0.0, 1.0);\ngui.set_color(node, red);"
|
|
474
|
+
}
|
|
475
|
+
],
|
|
476
|
+
"gui.new_texture": [
|
|
477
|
+
{
|
|
478
|
+
"sourceHash": "192ba6f4b864704a",
|
|
479
|
+
"ts": "// How to create a texture and apply it to a new box node:\nexport default defineScript({\n init(self) {\n const w = 200;\n const h = 300;\n\n // A nice orange. String with the RGB values.\n const orange = String.fromCharCode(0xff, 0x80, 0x10);\n\n // Create the texture. Repeat the color string for each pixel.\n const [ok, reason] = gui.new_texture(\"orange_tx\", w, h, \"rgb\", orange.repeat(w * h));\n if (ok) {\n // Create a box node and apply the texture to it.\n const n = gui.new_box_node(vmath.vector3(200, 200, 0), vmath.vector3(w, h, 0));\n gui.set_texture(n, \"orange_tx\");\n } else {\n // Could not create texture for some reason...\n if (reason === gui.RESULT_TEXTURE_ALREADY_EXISTS) {\n // ...\n } else {\n // ...\n }\n }\n },\n});\n\n// How to create a texture using .astc format\nconst path = \"/assets/images/logo_4x4.astc\";\nconst buffer = sys.load_resource(path);\nconst n = gui.new_box_node(pos, vmath.vector3(size, size, 0));\n// size is read from the .astc buffer\n// flip is not supported\ngui.new_texture(path, 0, 0, \"astc\", buffer, false);\ngui.set_texture(n, path);"
|
|
480
|
+
}
|
|
481
|
+
],
|
|
482
|
+
"gui.play_flipbook": [
|
|
483
|
+
{
|
|
484
|
+
"sourceHash": "341233e631c23020",
|
|
485
|
+
"ts": "// Set the texture of a node to a flipbook animation from an atlas:\nfunction anim_callback(self, node) {\n // Take action after animation has played.\n}\n\nexport default defineScript({\n init(self) {\n // Create a new node and set the texture to a flipbook animation\n const node = gui.get_node(\"button_node\");\n gui.set_texture(node, \"gui_sprites\");\n gui.play_flipbook(node, \"animated_button\");\n },\n});\n\n// Set the texture of a node to an image from an atlas:\n// Create a new node and set the texture to a \"button.png\" from atlas\nconst node = gui.get_node(\"button_node\");\ngui.set_texture(node, \"gui_sprites\");\ngui.play_flipbook(node, \"button\");"
|
|
486
|
+
}
|
|
487
|
+
],
|
|
488
|
+
"gui.play_particlefx": [
|
|
489
|
+
{
|
|
490
|
+
"sourceHash": "19a26b6e14ad0997",
|
|
491
|
+
"ts": "// How to play a particle fx when a gui node is created.\n// The callback receives the gui node, the hash of the id\n// of the emitter, and the new state of the emitter as particlefx.EMITTER_STATE_.\nfunction emitter_state_change(self, node, emitter, state) {\n if (emitter === hash(\"exhaust\") && state === particlefx.EMITTER_STATE_POSTSPAWN) {\n // exhaust is done spawning particles...\n }\n}\n\nexport default defineScript({\n init(self) {\n gui.play_particlefx(gui.get_node(\"particlefx\"), emitter_state_change);\n },\n});"
|
|
492
|
+
}
|
|
493
|
+
],
|
|
494
|
+
"gui.reset_material": [
|
|
495
|
+
{
|
|
496
|
+
"sourceHash": "3f3b1b3bdeb1ec73",
|
|
497
|
+
"ts": "// Resetting the material for a node:\nconst node = gui.get_node(\"my_node\");\ngui.reset_material(node);"
|
|
498
|
+
}
|
|
499
|
+
],
|
|
500
|
+
"gui.screen_to_local": [
|
|
501
|
+
{
|
|
502
|
+
"sourceHash": "3e442324e48a7f04",
|
|
503
|
+
"ts": "// Animate a node to the pressed pointer position:\nexport default defineScript({\n init() {\n msg.post(\".\", \"acquire_input_focus\");\n return { marker: gui.get_node(\"marker\") };\n },\n\n on_input(self, action_id, action) {\n if (action_id === hash(\"touch\") && action.pressed) {\n const screen_position = vmath.vector3(action.screen_x, action.screen_y, 0);\n const target_position = gui.screen_to_local(self.marker, screen_position);\n gui.animate(self.marker, gui.PROP_POSITION, target_position, gui.EASING_OUTQUAD, 0.2);\n return true;\n }\n },\n});"
|
|
504
|
+
}
|
|
505
|
+
],
|
|
506
|
+
"gui.set": [
|
|
507
|
+
{
|
|
508
|
+
"sourceHash": "a609fdbcee772fac",
|
|
509
|
+
"ts": "// Updates the position property on an existing node:\nconst node = gui.get_node(\"my_box_node\");\nconst node_position = gui.get(node, \"position\");\ngui.set(node, \"position.x\", node_position.x + 128);\n\n// Updates the rotation property on an existing node:\ngui.set(node, \"rotation\", vmath.quat_rotation_z(math.rad(45)));\n// this is equivalent to:\ngui.set(node, \"euler.z\", 45);\n// or using the entire vector:\ngui.set(node, \"euler\", vmath.vector3(0, 0, 45));\n// or using the set_rotation\ngui.set_rotation(node, vmath.vector3(0, 0, 45));\n\n// Sets various material constants for a node:\ngui.set(node, \"tint\", vmath.vector4(1, 0, 0, 1));\n// matrix4 is also supported\ngui.set(node, \"light_matrix\", vmath.matrix4());\n// update a constant in an array at position 4. the array is specified in the shader as:\n// uniform vec4 tint_array[4]; // lua is 1 based, shader is 0 based\ngui.set(node, \"tint_array\", vmath.vector4(1, 0, 0, 1), { index: 4 });\n// update a matrix constant in an array at position 4. the array is specified in the shader as:\n// uniform mat4 light_matrix_array[4];\ngui.set(node, \"light_matrix_array\", vmath.matrix4(), { index: 4 });\n// update a sub-element in a constant\ngui.set(node, \"tint.x\", 1);\n// update a sub-element in an array constant at position 4\ngui.set(node, \"tint_array.x\", 1, { index: 4 });\n\n// Set a named property\nexport default defineScript({\n on_message(self, message_id, message) {\n if (message_id === hash(\"set_font\")) {\n gui.set(msg.url(), \"fonts\", message.font, { key: \"my_font_name\" });\n gui.set_font(gui.get_node(\"text\"), \"my_font_name\");\n } else if (message_id === hash(\"set_texture\")) {\n gui.set(msg.url(), \"textures\", message.texture, { key: \"my_texture\" });\n gui.set_texture(gui.get_node(\"box\"), \"my_texture\");\n gui.play_flipbook(gui.get_node(\"box\"), \"logo_256\");\n }\n },\n});\n\n// Remove a named runtime texture resource mapping:\nconst atlas_id = resource.create_atlas(\"/runtime.texturesetc\", atlas_params);\ngui.set(msg.url(), \"textures\", atlas_id, { key: \"runtime_texture\" });\ngui.set_texture(gui.get_node(\"box\"), \"runtime_texture\");\n\n// Later, remove the GUI mapping before releasing the atlas resource.\ngui.set(msg.url(), \"textures\", undefined, { key: \"runtime_texture\" });\nresource.release(atlas_id);"
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
"sourceHash": "d195edde0a9fd170",
|
|
513
|
+
"ts": "// Updates the position property on an existing node:\nconst node = gui.get_node(\"my_box_node\");\nconst node_position = gui.get(node, \"position\");\ngui.set(node, \"position.x\", node_position.x + 128);\n\n// Updates the rotation property on an existing node:\ngui.set(node, \"rotation\", vmath.quat_rotation_z(math.rad(45)));\n// this is equivalent to:\ngui.set(node, \"euler.z\", 45);\n// or using the entire vector:\ngui.set(node, \"euler\", vmath.vector3(0, 0, 45));\n// or using the set_rotation\ngui.set_rotation(node, vmath.vector3(0, 0, 45));\n\n// Sets various material constants for a node:\ngui.set(node, \"tint\", vmath.vector4(1, 0, 0, 1));\n// matrix4 is also supported\ngui.set(node, \"light_matrix\", vmath.matrix4());\n// update a constant in an array at position 4. the array is specified in the shader as:\n// uniform vec4 tint_array[4]; // lua is 1 based, shader is 0 based\ngui.set(node, \"tint_array\", vmath.vector4(1, 0, 0, 1), { index: 4 });\n// update a matrix constant in an array at position 4. the array is specified in the shader as:\n// uniform mat4 light_matrix_array[4];\ngui.set(node, \"light_matrix_array\", vmath.matrix4(), { index: 4 });\n// update a sub-element in a constant\ngui.set(node, \"tint.x\", 1);\n// update a sub-element in an array constant at position 4\ngui.set(node, \"tint_array.x\", 1, { index: 4 });\n\n// Set a named property\nexport default defineScript({\n on_message(self, message_id, message) {\n if (message_id === hash(\"set_font\")) {\n gui.set(msg.url(), \"fonts\", message.font, { key: \"my_font_name\" });\n gui.set_font(gui.get_node(\"text\"), \"my_font_name\");\n } else if (message_id === hash(\"set_texture\")) {\n gui.set(msg.url(), \"textures\", message.texture, { key: \"my_texture\" });\n gui.set_texture(gui.get_node(\"box\"), \"my_texture\");\n gui.play_flipbook(gui.get_node(\"box\"), \"logo_256\");\n }\n },\n});"
|
|
514
|
+
}
|
|
515
|
+
],
|
|
516
|
+
"gui.set_id": [
|
|
517
|
+
{
|
|
518
|
+
"sourceHash": "a17e8e54c0bba6b7",
|
|
519
|
+
"ts": "// Create a new node and set its id:\nconst pos = vmath.vector3(100, 100, 0);\nconst size = vmath.vector3(100, 100, 0);\nconst node = gui.new_box_node(pos, size);\ngui.set_id(node, \"my_new_node\");"
|
|
520
|
+
}
|
|
521
|
+
],
|
|
522
|
+
"gui.set_material": [
|
|
523
|
+
{
|
|
524
|
+
"sourceHash": "891af31360f6d071",
|
|
525
|
+
"ts": "// Assign an existing material to a node:\nconst node = gui.get_node(\"my_node\");\ngui.set_material(node, \"my_material\");"
|
|
526
|
+
}
|
|
527
|
+
],
|
|
528
|
+
"gui.set_texture": [
|
|
529
|
+
{
|
|
530
|
+
"sourceHash": "8c3b738f1772c4fa",
|
|
531
|
+
"ts": "// To set a texture (or animation) from an atlas:\nconst node = gui.get_node(\"box_node\");\ngui.set_texture(node, \"my_atlas\");\ngui.play_flipbook(node, \"image\");\n\n// Set a dynamically created texture to a node. Note that there is only\n// one texture image in this case so gui.set_texture() is sufficient.\nconst w = 200;\nconst h = 300;\n// A nice orange. String with the RGB values.\nconst orange = String.fromCharCode(0xff, 0x80, 0x10);\n// Create the texture. Repeat the color string for each pixel.\nif (gui.new_texture(\"orange_tx\", w, h, \"rgb\", orange.repeat(w * h))) {\n gui.set_texture(node, \"orange_tx\");\n}"
|
|
532
|
+
}
|
|
533
|
+
],
|
|
534
|
+
"gui.set_texture_data": [
|
|
535
|
+
{
|
|
536
|
+
"sourceHash": "86e3fd4362242ba1",
|
|
537
|
+
"ts": "export default defineScript({\n init(self) {\n const w = 200;\n const h = 300;\n\n // Create a dynamic texture, all white.\n if (gui.new_texture(\"dynamic_tx\", w, h, \"rgb\", String.fromCharCode(0xff).repeat(w * h * 3))) {\n // Create a box node and apply the texture to it.\n const n = gui.new_box_node(vmath.vector3(200, 200, 0), vmath.vector3(w, h, 0));\n gui.set_texture(n, \"dynamic_tx\");\n\n // ...\n\n // Change the data in the texture to a nice orange.\n const orange = String.fromCharCode(0xff, 0x80, 0x10);\n if (gui.set_texture_data(\"dynamic_tx\", w, h, \"rgb\", orange.repeat(w * h))) {\n // Go on and to more stuff\n // ...\n }\n } else {\n // Something went wrong\n // ...\n }\n },\n});"
|
|
538
|
+
}
|
|
539
|
+
],
|
|
540
|
+
"html5.run": [
|
|
541
|
+
{
|
|
542
|
+
"sourceHash": "03f87c9fc915512f",
|
|
543
|
+
"ts": "const res = html5.run(\"10 + 20\"); // returns the string \"30\"\nprint(res);\nconst res_num = tonumber(res); // convert to number\nprint(res_num - 20); // prints 10"
|
|
544
|
+
}
|
|
545
|
+
],
|
|
546
|
+
"html5.set_interaction_listener": [
|
|
547
|
+
{
|
|
548
|
+
"sourceHash": "edc07489a3fc761c",
|
|
549
|
+
"ts": "function on_interaction(self) {\n print(\"on_interaction called\");\n html5.set_interaction_listener(undefined);\n}\n\nexport default defineScript({\n init() {\n html5.set_interaction_listener(on_interaction);\n },\n});"
|
|
550
|
+
}
|
|
551
|
+
],
|
|
552
|
+
"http.request": [
|
|
553
|
+
{
|
|
554
|
+
"sourceHash": "170c94c250c1ce49",
|
|
555
|
+
"ts": "// Basic HTTP-GET request. The callback receives a table with the response\n// in the fields status, the response (the data) and headers (a table).\nexport default defineScript({\n init() {\n http.request(\n \"http://www.google.com\",\n \"GET\",\n (self, _id, response) => {\n if (response.bytes_total !== undefined) {\n update_my_progress_bar(self, response.bytes_received / response.bytes_total);\n } else {\n print(response.status);\n print(response.response);\n pprint(response.headers);\n }\n },\n undefined,\n undefined,\n { report_progress: true },\n );\n },\n});"
|
|
556
|
+
}
|
|
557
|
+
],
|
|
558
|
+
"image.get_astc_header": [
|
|
559
|
+
{
|
|
560
|
+
"sourceHash": "adae89354a89050a",
|
|
561
|
+
"ts": "// How to get the block size and dimensions from a .astc file\nconst [s] = sys.load_resource(\"/assets/cat.astc\");\nconst header = image.get_astc_header(s);\npprint(s);"
|
|
562
|
+
}
|
|
563
|
+
],
|
|
564
|
+
"image.load": [
|
|
565
|
+
{
|
|
566
|
+
"sourceHash": "d7c6b4708bd86c99",
|
|
567
|
+
"ts": "// How to load an image from an URL and create a GUI texture from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img = image.load(response.response);\n const tx = gui.new_texture(\"image_node\", img.width, img.height, img.type, img.buffer);\n});"
|
|
568
|
+
}
|
|
569
|
+
],
|
|
570
|
+
"image.load_buffer": [
|
|
571
|
+
{
|
|
572
|
+
"sourceHash": "55649cadc660e25e",
|
|
573
|
+
"ts": "// Load an image from an URL as a buffer and create a texture resource from it:\nconst imgurl = \"http://www.site.com/image.png\";\nhttp.request(imgurl, \"GET\", (self, id, response) => {\n const img = image.load_buffer(response.response, { flip_vertically: true });\n const tparams = {\n width: img.width,\n height: img.height,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA,\n };\n\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams, img.buffer);\n // Apply the texture to a model\n go.set(\"/go1#model\", \"texture0\", my_texture_id);\n});"
|
|
574
|
+
}
|
|
575
|
+
],
|
|
576
|
+
"init": [
|
|
577
|
+
{
|
|
578
|
+
"sourceHash": "70267e467e6e247e",
|
|
579
|
+
"ts": "export default defineScript({\n init() {\n // set up useful data\n return { my_value: 1 };\n },\n});"
|
|
580
|
+
}
|
|
581
|
+
],
|
|
582
|
+
"json.decode": [
|
|
583
|
+
{
|
|
584
|
+
"sourceHash": "a9970c96ca5954c6",
|
|
585
|
+
"ts": "// Converting a string containing JSON data into a table:\nexport default defineScript({\n init() {\n const jsonstring = '{\"persons\":[{\"name\":\"John Doe\"},{\"name\":\"Darth Vader\"}]}';\n const data = json.decode(jsonstring);\n pprint(data);\n },\n});\n\n// Results in the following printout:\n// {\n// persons = {\n// 1 = {\n// name = John Doe,\n// }\n// 2 = {\n// name = Darth Vader,\n// }\n// }\n// }"
|
|
586
|
+
}
|
|
587
|
+
],
|
|
588
|
+
"json.encode": [
|
|
589
|
+
{
|
|
590
|
+
"sourceHash": "e87a21865ef89cd4",
|
|
591
|
+
"ts": "// Convert a table to a JSON string:\nexport default defineScript({\n init() {\n const tbl = {\n persons: [{ name: \"John Doe\" }, { name: \"Darth Vader\" }],\n };\n const jsonstring = json.encode(tbl);\n pprint(jsonstring);\n },\n});\n\n// Results in the following printout:\n// {\"persons\":[{\"name\":\"John Doe\"},{\"name\":\"Darth Vader\"}]}"
|
|
592
|
+
}
|
|
593
|
+
],
|
|
594
|
+
"label.get_text": [
|
|
595
|
+
{
|
|
596
|
+
"sourceHash": "f1c34d0aca8a07d9",
|
|
597
|
+
"ts": "export default defineScript({\n init(self) {\n const text = label.get_text(\"#label\");\n print(text);\n },\n});"
|
|
598
|
+
}
|
|
599
|
+
],
|
|
600
|
+
"label.set_text": [
|
|
601
|
+
{
|
|
602
|
+
"sourceHash": "0d47c9a209b0d646",
|
|
603
|
+
"ts": "export default defineScript({\n init(self) {\n label.set_text(\"#label\", \"Hello World!\");\n },\n});"
|
|
604
|
+
}
|
|
605
|
+
],
|
|
606
|
+
"liveupdate.add_mount": [
|
|
607
|
+
{
|
|
608
|
+
"sourceHash": "708a62d425220ddf",
|
|
609
|
+
"ts": "// Add multiple mounts. Higher priority takes precedence.\nliveupdate.add_mount(\"common\", \"zip:/path/to/common_stuff.zip\", 10, (result) => {}); // base pack\nliveupdate.add_mount(\"levelpack_1\", \"zip:/path/to/levels_1_to_20.zip\", 20, (result) => {}); // level pack\nliveupdate.add_mount(\"season_pack_1\", \"zip:/path/to/easter_pack_1.zip\", 30, (result) => {}); // season pack, overriding content in the other packs"
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
"sourceHash": "71fa57cf1b09f936",
|
|
613
|
+
"ts": "// Add multiple mounts. Higher priority takes precedence.\nliveupdate.add_mount(\"common\", \"zip:/path/to/common_stuff.zip\", 10, (result) => {}); // base pack\nliveupdate.add_mount(\"levelpack_1\", \"zip:/path/to/levels_1_to_20.zip\", 20, (result) => {}); // level pack\nliveupdate.add_mount(\"season_pack_1\", \"zip:/path/to/easter_pack_1.zip\", 30, (result) => {}); // season pack, overriding content in the other packs"
|
|
614
|
+
}
|
|
615
|
+
],
|
|
616
|
+
"liveupdate.get_mounts": [
|
|
617
|
+
{
|
|
618
|
+
"sourceHash": "1d7c8369562acce9",
|
|
619
|
+
"ts": "// Output the current resource mounts\npprint(\"MOUNTS\", liveupdate.get_mounts());\n\n// Give an output like:\n// DEBUG:SCRIPT: MOUNTS,\n// {\n// 1 = {\n// name = \"liveupdate\",\n// uri = \"zip:/device/path/to/acchives/liveupdate.zip\",\n// priority = 5\n// },\n// 2 = {\n// name = \"_base\",\n// uri = \"archive:build/default/game.dmanifest\",\n// priority = -10\n// }\n// }"
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
"sourceHash": "f79283b7edf516cf",
|
|
623
|
+
"ts": "// Output the current resource mounts\npprint(\"MOUNTS\", liveupdate.get_mounts());\n\n// Give an output like:\n// DEBUG:SCRIPT: MOUNTS,\n// {\n// 1 = {\n// name = \"liveupdate\",\n// uri = \"zip:/device/path/to/acchives/liveupdate.zip\",\n// priority = 5\n// },\n// 2 = {\n// name = \"_base\",\n// uri = \"archive:build/default/game.dmanifest\",\n// priority = -10\n// }\n// }"
|
|
624
|
+
}
|
|
625
|
+
],
|
|
626
|
+
"liveupdate.is_built_with_excluded_files": [
|
|
627
|
+
{
|
|
628
|
+
"sourceHash": "dc3945dfc9f5899a",
|
|
629
|
+
"ts": "if (liveupdate.is_built_with_excluded_files()) print(\"The bundle expects live update content.\");"
|
|
630
|
+
}
|
|
631
|
+
],
|
|
632
|
+
"liveupdate.remove_mount": [
|
|
633
|
+
{
|
|
634
|
+
"sourceHash": "4cd05fc6a53a9964",
|
|
635
|
+
"ts": "// Add multiple mounts. Higher priority takes precedence.\nliveupdate.remove_mount(\"season_pack_1\");"
|
|
636
|
+
}
|
|
637
|
+
],
|
|
638
|
+
"material.get_constants": [
|
|
639
|
+
{
|
|
640
|
+
"sourceHash": "6409de8793053165",
|
|
641
|
+
"ts": "const constants = material.get_constants(resource.material(\"/my_material.materialc\"));"
|
|
642
|
+
}
|
|
643
|
+
],
|
|
644
|
+
"material.get_samplers": [
|
|
645
|
+
{
|
|
646
|
+
"sourceHash": "e346ac9f6ec55d31",
|
|
647
|
+
"ts": "const samplers = material.get_samplers(resource.material(\"/my_material.materialc\"));"
|
|
648
|
+
}
|
|
649
|
+
],
|
|
650
|
+
"material.get_textures": [
|
|
651
|
+
{
|
|
652
|
+
"sourceHash": "350415f3b2ba725d",
|
|
653
|
+
"ts": "const textures = material.get_textures(resource.material(\"/my_material.materialc\"));"
|
|
654
|
+
}
|
|
655
|
+
],
|
|
656
|
+
"material.get_vertex_attributes": [
|
|
657
|
+
{
|
|
658
|
+
"sourceHash": "e835376dd87b4332",
|
|
659
|
+
"ts": "const vertex_attributes = material.get_vertex_attributes(resource.material(\"/my_material.materialc\"));"
|
|
660
|
+
}
|
|
661
|
+
],
|
|
662
|
+
"material.set_constants": [
|
|
663
|
+
{
|
|
664
|
+
"sourceHash": "4f7ec4631253a3dc",
|
|
665
|
+
"ts": "material.set_constants(resource.material(\"/my_material.materialc\"), { tint: { value: vmath.vector4(1, 0, 0, 1) } });"
|
|
666
|
+
}
|
|
667
|
+
],
|
|
668
|
+
"material.set_samplers": [
|
|
669
|
+
{
|
|
670
|
+
"sourceHash": "3d29dbd58cf503ad",
|
|
671
|
+
"ts": "material.set_samplers(resource.material(\"/my_material.materialc\"), { texture_sampler: { u_wrap: graphics.TEXTURE_WRAP_REPEAT, v_wrap: graphics.TEXTURE_WRAP_MIRRORED_REPEAT } });"
|
|
672
|
+
}
|
|
673
|
+
],
|
|
674
|
+
"material.set_textures": [
|
|
675
|
+
{
|
|
676
|
+
"sourceHash": "8b7930f275efc915",
|
|
677
|
+
"ts": "material.set_textures(resource.material(\"/my_material.materialc\"), { my_texture: resource.texture() });"
|
|
678
|
+
}
|
|
679
|
+
],
|
|
680
|
+
"material.set_vertex_attributes": [
|
|
681
|
+
{
|
|
682
|
+
"sourceHash": "a78800caef15ee12",
|
|
683
|
+
"ts": "material.set_vertex_attributes(resource.material(\"/my_material.materialc\"), { tint_attribute: { value: vmath.vector4(1, 0, 0, 1), semantic_type: graphics.SEMANTIC_TYPE_COLOR } });"
|
|
684
|
+
}
|
|
685
|
+
],
|
|
686
|
+
"model.get_aabb": [
|
|
687
|
+
{
|
|
688
|
+
"sourceHash": "c3d5a35355bc45dd",
|
|
689
|
+
"ts": "model.get_aabb(\"#model\"); // => { min = vmath.vector3(-2.5, -3.0, 0), max = vmath.vector3(1.5, 5.5, 0) }\nmodel.get_aabb(\"#empty\"); // => { min = vmath.vector3(0, 0, 0), max = vmath.vector3(0, 0, 0) }"
|
|
690
|
+
}
|
|
691
|
+
],
|
|
692
|
+
"model.get_blend_weights": [
|
|
693
|
+
{
|
|
694
|
+
"sourceHash": "a4945bd4efb90dd9",
|
|
695
|
+
"ts": "const weights = model.get_blend_weights(\"#model\");\nweights[1] = 0.75;\nweights[2] = 0.25;\nmodel.set_blend_weights(\"#model\", weights);"
|
|
696
|
+
}
|
|
697
|
+
],
|
|
698
|
+
"model.get_go": [
|
|
699
|
+
{
|
|
700
|
+
"sourceHash": "dc474f0980c842b4",
|
|
701
|
+
"ts": "// The following examples assume that the model component has id \"model\".\n// How to parent the game object of the calling script to the \"right_hand\" bone\n// of the model in a player game object:\nexport default defineScript({\n init(self) {\n const parent = model.get_go(\"player#model\", \"right_hand\");\n msg.post(\".\", \"set_parent\", { parent_id: parent });\n },\n});"
|
|
702
|
+
}
|
|
703
|
+
],
|
|
704
|
+
"model.get_mesh_aabb": [
|
|
705
|
+
{
|
|
706
|
+
"sourceHash": "4271f0cc5563f9e2",
|
|
707
|
+
"ts": "model.get_mesh_aabb(\"#model\"); // => { hash(\"Sword\") = { min = vmath.vector3(-0.5, -0.5, 0), max = vmath.vector3(0.5, 0.5, 0) }, hash(\"Shield\") = { min = vmath.vector3(-0.5, -0.5, -0.5), max = vmath.vector3(0.5, 0.5, 0.5) } }"
|
|
708
|
+
}
|
|
709
|
+
],
|
|
710
|
+
"model.get_mesh_enabled": [
|
|
711
|
+
{
|
|
712
|
+
"sourceHash": "b2f9e47a91bc3f12",
|
|
713
|
+
"ts": "export default defineScript({\n init(self) {\n if (model.get_mesh_enabled(\"#model\", \"Sword\")) {\n // set properties specific for the sword\n self.weapon_properties = game.data.weapons[\"Sword\"];\n }\n },\n});"
|
|
714
|
+
}
|
|
715
|
+
],
|
|
716
|
+
"model.play_anim": [
|
|
717
|
+
{
|
|
718
|
+
"sourceHash": "64d6b46054d23a1b",
|
|
719
|
+
"ts": "// The following examples assume that the model has id \"model\".\n// How to play the \"jump\" animation followed by the \"run\" animation:\nfunction anim_done(self, message_id, message, sender) {\n if (message_id === hash(\"model_animation_done\")) {\n if (message.animation_id === hash(\"jump\")) {\n // open animation done, chain with \"run\"\n const properties = { blend_duration: 0.2 };\n model.play_anim(url, \"run\", go.PLAYBACK_LOOP_FORWARD, properties, anim_done);\n }\n }\n}\n\nexport default defineScript({\n init(self) {\n const url = msg.url(\"#model\");\n const play_properties = { blend_duration: 0.1 };\n // first blend during 0.1 sec into the jump, then during 0.2 s into the run animation\n model.play_anim(url, \"jump\", go.PLAYBACK_ONCE_FORWARD, play_properties, anim_done);\n },\n});"
|
|
720
|
+
}
|
|
721
|
+
],
|
|
722
|
+
"model.reset_constant": [
|
|
723
|
+
{
|
|
724
|
+
"sourceHash": "969baf429fe024b8",
|
|
725
|
+
"ts": "model.reset_constant(\"#model\", \"tint\");"
|
|
726
|
+
}
|
|
727
|
+
],
|
|
728
|
+
"model.set_blend_weights": [
|
|
729
|
+
{
|
|
730
|
+
"sourceHash": "74fd31c0afc44481",
|
|
731
|
+
"ts": "model.set_blend_weights(\"#model\", [0, 1, 0.5, 0]);\nmodel.set_blend_weights(\"#model\");"
|
|
732
|
+
}
|
|
733
|
+
],
|
|
734
|
+
"model.set_mesh_enabled": [
|
|
735
|
+
{
|
|
736
|
+
"sourceHash": "a941b97305e37153",
|
|
737
|
+
"ts": "export default defineScript({\n init(self) {\n model.set_mesh_enabled(\"#model\", \"Sword\", false); // hide the sword\n model.set_mesh_enabled(\"#model\", \"Axe\", true); // show the axe\n },\n});"
|
|
738
|
+
}
|
|
739
|
+
],
|
|
740
|
+
"msg.post": [
|
|
741
|
+
{
|
|
742
|
+
"sourceHash": "8eb90635d0b538fe",
|
|
743
|
+
"ts": "// Send \"enable\" to the sprite \"my_sprite\" in \"my_gameobject\":\nmsg.post(\"my_gameobject#my_sprite\", \"enable\");\n\n// Send a \"my_message\" to a url with some additional data:\nconst params = { my_parameter: \"my_value\" };\nmsg.post(my_url, \"my_message\", params);"
|
|
744
|
+
}
|
|
745
|
+
],
|
|
746
|
+
"msg.url": [
|
|
747
|
+
{
|
|
748
|
+
"sourceHash": "beb786e09647d2ac",
|
|
749
|
+
"ts": "const my_socket = \"main\"; // specify by valid name\nconst my_path = hash(\"/my_collection/my_gameobject\"); // specify as string or hash\nconst my_fragment = \"component\"; // specify as string or hash\nconst my_url = msg.url(my_socket, my_path, my_fragment);\n\nprint(my_url); // => url: [main:/my_collection/my_gameobject#component]\nprint(my_url.socket); // => 786443 (internal numeric value)\nprint(my_url.path); // => hash: [/my_collection/my_gameobject]\nprint(my_url.fragment); // => hash: [component]"
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
"sourceHash": "10aea53cabfa253d",
|
|
753
|
+
"ts": "// Create a new URL which will address the current script:\nconst my_url = msg.url();\nprint(my_url); // => url: [current_collection:/my_instance#my_component]"
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
"sourceHash": "ceb19017beed7eef",
|
|
757
|
+
"ts": "const my_url = msg.url(\"#my_component\");\nprint(my_url); // => url: [current_collection:/my_instance#my_component]\n\nconst my_collection_url = msg.url(\"my_collection:/my_sub_collection/my_instance#my_component\");\nprint(my_collection_url); // => url: [my_collection:/my_sub_collection/my_instance#my_component]\n\nconst my_socket_url = msg.url(\"my_socket:\");\nprint(my_socket_url); // => url: [my_collection:]"
|
|
758
|
+
}
|
|
759
|
+
],
|
|
760
|
+
"on_input": [
|
|
761
|
+
{
|
|
762
|
+
"sourceHash": "86c70cf4ccb7381e",
|
|
763
|
+
"ts": "// This example demonstrates how a game object instance can be moved as a response to user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);\n }\n }\n },\n});"
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
"sourceHash": "cc835ea429adc693",
|
|
767
|
+
"ts": "export default defineScript({\n on_input(self, action_id, action) {\n // check for input\n if (action_id === hash(\"my_action\")) {\n // take appropriate action\n self.my_value = action.value;\n }\n // consume input\n return true;\n },\n});"
|
|
768
|
+
}
|
|
769
|
+
],
|
|
770
|
+
"on_message": [
|
|
771
|
+
{
|
|
772
|
+
"sourceHash": "bfed6bd72e3242e2",
|
|
773
|
+
"ts": "// This example demonstrates how a game object instance, called \"a\", can communicate with another instance, called \"b\". It\n// is assumed that both script components of the instances has id \"script\".\n\n// a.script \u2014 Script of instance \"a\":\nexport default defineScript({\n init() {\n // let b know about some important data\n msg.post(\"b#script\", \"my_data\", { important_value: 1 });\n },\n});\n\n// b.script \u2014 Script of instance \"b\":\nexport default defineScript({\n init() {\n // store the url of instance \"a\" for later use, by specifying undefined as socket we\n // automatically use our own socket\n return { a_url: msg.url(undefined, go.get_id(\"a\"), \"script\") };\n },\n\n on_message(self, message_id, message, sender) {\n // check message and sender\n if (message_id === hash(\"my_data\") && sender === self.a_url) {\n // use the data in some way\n self.important_value = message.important_value;\n }\n },\n});"
|
|
774
|
+
}
|
|
775
|
+
],
|
|
776
|
+
"on_reload": [
|
|
777
|
+
{
|
|
778
|
+
"sourceHash": "ba39c0b0d5170ccb",
|
|
779
|
+
"ts": "// This example demonstrates how to tweak the speed of a game object instance that is moved on user input.\nexport default defineScript({\n init() {\n // acquire input focus\n msg.post(\".\", \"acquire_input_focus\");\n return {\n // maximum speed the instance can be moved, this value is tweaked in the on_reload function below\n max_speed: 2,\n // velocity of the instance, initially zero\n velocity: vmath.vector3(),\n };\n },\n\n update(self, dt) {\n // move the instance\n go.set_position(go.get_position().add(self.velocity.mul(dt)));\n },\n\n on_input(self, action_id, action) {\n // check for movement input\n if (action_id === hash(\"right\")) {\n if (action.released) {\n // reset velocity if input was released\n self.velocity = vmath.vector3();\n } else {\n // update velocity\n self.velocity = vmath.vector3(action.value * self.max_speed, 0, 0);\n }\n }\n },\n\n on_reload(self) {\n // edit this value and reload the script component\n self.max_speed = 100;\n },\n});"
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
"sourceHash": "e89fe0d0bd51ed98",
|
|
783
|
+
"ts": "export default defineGuiScript({\n on_reload(self) {\n // restore some color (or similar)\n gui.set_color(gui.get_node(\"my_node\"), self.my_original_color);\n },\n});"
|
|
784
|
+
}
|
|
785
|
+
],
|
|
786
|
+
"particlefx.play": [
|
|
787
|
+
{
|
|
788
|
+
"sourceHash": "01a21997b47ac4fc",
|
|
789
|
+
"ts": "// How to play a particle fx when a game object is created.\n// The callback receives the hash of the path to the particlefx, the hash of the id\n// of the emitter, and the new state of the emitter as particlefx.EMITTER_STATE_.\nfunction emitter_state_change(self, id, emitter, state) {\n if (emitter === hash(\"exhaust\") && state === particlefx.EMITTER_STATE_POSTSPAWN) {\n // exhaust is done spawning particles...\n }\n}\n\nexport default defineScript({\n init(self) {\n particlefx.play(\"#particlefx\", emitter_state_change);\n },\n});"
|
|
790
|
+
}
|
|
791
|
+
],
|
|
792
|
+
"particlefx.reset_constant": [
|
|
793
|
+
{
|
|
794
|
+
"sourceHash": "f633633f9123cbd5",
|
|
795
|
+
"ts": "// The following examples assume that the particle FX has id \"particlefx\", it\n// contains an emitter with the id \"emitter\" and that the default-material in\n// builtins is used, which defines the constant \"tint\".\n// If you assign a custom material to the sprite, you can reset the constants\n// defined there in the same manner.\n// How to reset the tinting of particles from an emitter:\nexport default defineScript({\n init(self) {\n particlefx.reset_constant(\"#particlefx\", \"emitter\", \"tint\");\n },\n});"
|
|
796
|
+
}
|
|
797
|
+
],
|
|
798
|
+
"particlefx.set_constant": [
|
|
799
|
+
{
|
|
800
|
+
"sourceHash": "00b20c7c62578c94",
|
|
801
|
+
"ts": "// The following examples assume that the particle FX has id \"particlefx\", it\n// contains an emitter with the id \"emitter\" and that the default-material in\n// builtins is used, which defines the constant \"tint\".\n// If you assign a custom material to the sprite, you can reset the constants\n// defined there in the same manner.\n// How to tint particles from an emitter red:\nexport default defineScript({\n init(self) {\n particlefx.set_constant(\"#particlefx\", \"emitter\", \"tint\", vmath.vector4(1, 0, 0, 1));\n },\n});"
|
|
802
|
+
}
|
|
803
|
+
],
|
|
804
|
+
"particlefx.stop": [
|
|
805
|
+
{
|
|
806
|
+
"sourceHash": "28a9bb656e324f8c",
|
|
807
|
+
"ts": "// How to stop a particle fx when a game object is deleted and immediately also\n// clear any spawned particles:\nexport default defineScript({\n final(self) {\n particlefx.stop(\"#particlefx\", { clear: true });\n },\n});"
|
|
808
|
+
}
|
|
809
|
+
],
|
|
810
|
+
"physics.get_gravity": [
|
|
811
|
+
{
|
|
812
|
+
"sourceHash": "b2b339f1ddd89a38",
|
|
813
|
+
"ts": "export default defineScript({\n init(self) {\n let gravity = physics.get_gravity();\n // Inverse gravity!\n gravity = -gravity;\n physics.set_gravity(gravity);\n },\n});"
|
|
814
|
+
}
|
|
815
|
+
],
|
|
816
|
+
"physics.raycast": [
|
|
817
|
+
{
|
|
818
|
+
"sourceHash": "3e0c534d741f0120",
|
|
819
|
+
"ts": "// How to perform a ray cast synchronously:\nexport default defineScript({\n init(self) {\n self.groups = [hash(\"world\"), hash(\"enemy\")];\n },\n\n update(self, dt) {\n // request ray cast\n const result = physics.raycast(from, to, self.groups, { all: true });\n if (result !== undefined) {\n // act on the hit (see 'ray_cast_response')\n for (const result of results) {\n handle_result(result);\n }\n }\n },\n});"
|
|
820
|
+
}
|
|
821
|
+
],
|
|
822
|
+
"physics.raycast_async": [
|
|
823
|
+
{
|
|
824
|
+
"sourceHash": "746b7900ebaa1f10",
|
|
825
|
+
"ts": "// How to perform a ray cast asynchronously:\nexport default defineScript({\n init(self) {\n self.my_groups = [hash(\"my_group1\"), hash(\"my_group2\")];\n },\n\n update(self, dt) {\n // request ray cast\n physics.raycast_async(my_start, my_end, self.my_groups);\n },\n\n on_message(self, message_id, message, sender) {\n // check for the response\n if (message_id === hash(\"ray_cast_response\")) {\n // act on the hit\n } else if (message_id === hash(\"ray_cast_missed\")) {\n // act on the miss\n }\n },\n});"
|
|
826
|
+
}
|
|
827
|
+
],
|
|
828
|
+
"physics.set_event_listener": [
|
|
829
|
+
{
|
|
830
|
+
"sourceHash": "5d31d05d52e50c3f",
|
|
831
|
+
"ts": "function physics_world_listener(self, events) {\n for (const event of events) {\n const event_type = event[\"type\"];\n if (event_type === hash(\"contact_point_event\")) {\n pprint(event);\n // {\n // distance = 2.1490633487701,\n // applied_impulse = 0\n // a = { --[[0x113f7c6c0]]\n // group = hash: [box],\n // id = hash: [/box]\n // mass = 0,\n // normal = vmath.vector3(0.379, 0.925, -0),\n // position = vmath.vector3(517.337, 235.068, 0),\n // instance_position = vmath.vector3(480, 144, 0),\n // relative_velocity = vmath.vector3(-0, -0, -0),\n // },\n // b = { --[[0x113f7c840]]\n // group = hash: [circle],\n // id = hash: [/circle]\n // mass = 0,\n // normal = vmath.vector3(-0.379, -0.925, 0),\n // position = vmath.vector3(517.337, 235.068, 0),\n // instance_position = vmath.vector3(-0.0021, 0, -0.0022),\n // relative_velocity = vmath.vector3(0, 0, 0),\n // },\n // }\n } else if (event === hash(\"collision_event\")) {\n pprint(event);\n // {\n // a = {\n // group = hash: [default],\n // position = vmath.vector3(183, 666, 0),\n // id = hash: [/go1]\n // },\n // b = {\n // group = hash: [default],\n // position = vmath.vector3(185, 704.05865478516, 0),\n // id = hash: [/go2]\n // }\n // }\n } else if (event === hash(\"trigger_event\")) {\n pprint(event);\n // {\n // enter = true,\n // b = {\n // group = hash: [default],\n // id = hash: [/go2]\n // },\n // a = {\n // group = hash: [default],\n // id = hash: [/go1]\n // }\n // },\n } else if (event === hash(\"ray_cast_response\")) {\n pprint(event);\n // {\n // group = hash: [default],\n // request_id = 0,\n // position = vmath.vector3(249.92222595215, 249.92222595215, 0),\n // fraction = 0.68759721517563,\n // normal = vmath.vector3(0, 1, 0),\n // id = hash: [/go]\n // }\n } else if (event === hash(\"ray_cast_missed\")) {\n pprint(event);\n // {\n // request_id = 0\n // },\n }\n }\n}\n\nexport default defineScript({\n init(self) {\n physics.set_event_listener(physics_world_listener);\n },\n});"
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
"sourceHash": "ac24712f2e988ba4",
|
|
835
|
+
"ts": "function physics_world_listener(self, events) {\n for (const event of events) {\n const event_type = event[\"type\"];\n if (event_type === hash(\"contact_point_event\")) {\n pprint(event);\n // {\n // distance = 2.1490633487701,\n // applied_impulse = 0\n // a = { --[[0x113f7c6c0]]\n // group = hash: [box],\n // id = hash: [/box]\n // mass = 0,\n // normal = vmath.vector3(0.379, 0.925, -0),\n // position = vmath.vector3(517.337, 235.068, 0),\n // instance_position = vmath.vector3(480, 144, 0),\n // relative_velocity = vmath.vector3(-0, -0, -0),\n // },\n // b = { --[[0x113f7c840]]\n // group = hash: [circle],\n // id = hash: [/circle]\n // mass = 0,\n // normal = vmath.vector3(-0.379, -0.925, 0),\n // position = vmath.vector3(517.337, 235.068, 0),\n // instance_position = vmath.vector3(-0.0021, 0, -0.0022),\n // relative_velocity = vmath.vector3(0, 0, 0),\n // },\n // }\n } else if (event === hash(\"collision_event\")) {\n pprint(event);\n // {\n // a = {\n // group = hash: [default],\n // position = vmath.vector3(183, 666, 0),\n // id = hash: [/go1]\n // },\n // b = {\n // group = hash: [default],\n // position = vmath.vector3(185, 704.05865478516, 0),\n // id = hash: [/go2]\n // }\n // }\n } else if (event === hash(\"trigger_event\")) {\n pprint(event);\n // {\n // enter = true,\n // b = {\n // group = hash: [default],\n // id = hash: [/go2]\n // },\n // a = {\n // group = hash: [default],\n // id = hash: [/go1]\n // }\n // },\n } else if (event === hash(\"ray_cast_response\")) {\n pprint(event);\n // {\n // group = hash: [default],\n // request_id = 0,\n // position = vmath.vector3(249.92222595215, 249.92222595215, 0),\n // fraction = 0.68759721517563,\n // normal = vmath.vector3(0, 1, 0),\n // id = hash: [/go]\n // }\n } else if (event === hash(\"ray_cast_missed\")) {\n pprint(event);\n // {\n // request_id = 0\n // },\n }\n }\n}\n\nexport default defineScript({\n init(self) {\n physics.set_event_listener(physics_world_listener);\n },\n});"
|
|
836
|
+
}
|
|
837
|
+
],
|
|
838
|
+
"physics.set_gravity": [
|
|
839
|
+
{
|
|
840
|
+
"sourceHash": "56e8aa8c11bcde7b",
|
|
841
|
+
"ts": "export default defineScript({\n init(self) {\n // Set \"upside down\" gravity for this collection.\n physics.set_gravity(vmath.vector3(0, 10.0, 0));\n },\n});"
|
|
842
|
+
}
|
|
843
|
+
],
|
|
844
|
+
"physics.set_hflip": [
|
|
845
|
+
{
|
|
846
|
+
"sourceHash": "71a627e46d2e651e",
|
|
847
|
+
"ts": "export default defineScript({\n init(self) {\n self.fliph = true; // set on some condition\n physics.set_hflip(\"#collisionobject\", self.fliph);\n },\n});"
|
|
848
|
+
}
|
|
849
|
+
],
|
|
850
|
+
"physics.set_vflip": [
|
|
851
|
+
{
|
|
852
|
+
"sourceHash": "7b5832955ec6635c",
|
|
853
|
+
"ts": "export default defineScript({\n init(self) {\n self.flipv = true; // set on some condition\n physics.set_vflip(\"#collisionobject\", self.flipv);\n },\n});"
|
|
854
|
+
}
|
|
855
|
+
],
|
|
856
|
+
"physics.update_mass": [
|
|
857
|
+
{
|
|
858
|
+
"sourceHash": "a14ee2d03aad6964",
|
|
859
|
+
"ts": "physics.update_mass(\"#collisionobject\", 14);"
|
|
860
|
+
}
|
|
861
|
+
],
|
|
862
|
+
"profiler.dump_frame": [
|
|
863
|
+
{
|
|
864
|
+
"sourceHash": "54342e4fc710032d",
|
|
865
|
+
"ts": "profiler.dump_frame();"
|
|
866
|
+
}
|
|
867
|
+
],
|
|
868
|
+
"profiler.enable": [
|
|
869
|
+
{
|
|
870
|
+
"sourceHash": "e1bfae1cc8bfaedd",
|
|
871
|
+
"ts": "// Show the profiler UI\nprofiler.enable(true);"
|
|
872
|
+
}
|
|
873
|
+
],
|
|
874
|
+
"profiler.enable_ui": [
|
|
875
|
+
{
|
|
876
|
+
"sourceHash": "65b549b66a4b72c2",
|
|
877
|
+
"ts": "// Show the profiler UI\nprofiler.enable_ui(true);"
|
|
878
|
+
}
|
|
879
|
+
],
|
|
880
|
+
"profiler.get_memory_usage": [
|
|
881
|
+
{
|
|
882
|
+
"sourceHash": "5c8e91a11be9384c",
|
|
883
|
+
"ts": "// Get memory usage before and after loading a collection:\nprint(profiler.get_memory_usage());\nmsg.post(\"#collectionproxy\", \"load\");\n// ...\nprint(profiler.get_memory_usage()); // will report a higher number than the initial call"
|
|
884
|
+
}
|
|
885
|
+
],
|
|
886
|
+
"profiler.log_text": [
|
|
887
|
+
{
|
|
888
|
+
"sourceHash": "86c7e0a666f0147e",
|
|
889
|
+
"ts": "profiler.log_text(`Event: ${name}`);"
|
|
890
|
+
}
|
|
891
|
+
],
|
|
892
|
+
"profiler.recorded_frame_count": [
|
|
893
|
+
{
|
|
894
|
+
"sourceHash": "9d55df4a00c36560",
|
|
895
|
+
"ts": "// Show the last recorded frame\nconst recorded_frame_count = profiler.recorded_frame_count();\nprofiler.view_recorded_frame(recorded_frame_count);"
|
|
896
|
+
}
|
|
897
|
+
],
|
|
898
|
+
"profiler.scope_begin": [
|
|
899
|
+
{
|
|
900
|
+
"sourceHash": "fa297bd541df8930",
|
|
901
|
+
"ts": "// Go back one frame\nprofiler.scope_begin(\"test_function\");\ntest_function();\nprofiler.scope_end();"
|
|
902
|
+
}
|
|
903
|
+
],
|
|
904
|
+
"profiler.set_ui_mode": [
|
|
905
|
+
{
|
|
906
|
+
"sourceHash": "0a22390ad4d7be84",
|
|
907
|
+
"ts": "function start_recording() {\n profiler.set_ui_mode(profiler.MODE_RECORD);\n}\n\nfunction stop_recording() {\n profiler.set_ui_mode(profiler.MODE_PAUSE);\n}"
|
|
908
|
+
}
|
|
909
|
+
],
|
|
910
|
+
"profiler.set_ui_view_mode": [
|
|
911
|
+
{
|
|
912
|
+
"sourceHash": "04c7cd061143b3b2",
|
|
913
|
+
"ts": "// Minimize the profiler view\nprofiler.set_ui_view_mode(profiler.VIEW_MODE_MINIMIZED);"
|
|
914
|
+
}
|
|
915
|
+
],
|
|
916
|
+
"profiler.set_ui_vsync_wait_visible": [
|
|
917
|
+
{
|
|
918
|
+
"sourceHash": "fa50cc9d8110ac3d",
|
|
919
|
+
"ts": "// Exclude frame wait time from the profiler ui\nprofiler.set_ui_vsync_wait_visible(false);"
|
|
920
|
+
}
|
|
921
|
+
],
|
|
922
|
+
"profiler.view_recorded_frame": [
|
|
923
|
+
{
|
|
924
|
+
"sourceHash": "3423bf00c5abd4cb",
|
|
925
|
+
"ts": "// Go back one frame\nprofiler.view_recorded_frame({ distance: -1 });"
|
|
926
|
+
}
|
|
927
|
+
],
|
|
928
|
+
"render.clear": [
|
|
929
|
+
{
|
|
930
|
+
"sourceHash": "70406f065fc91216",
|
|
931
|
+
"ts": "// Clear the color buffer and the depth buffer.\nrender.clear({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: vmath.vector4(0, 0, 0, 0),\n [graphics.BUFFER_TYPE_DEPTH_BIT]: 1,\n});"
|
|
932
|
+
}
|
|
933
|
+
],
|
|
934
|
+
"render.constant_buffer": [
|
|
935
|
+
{
|
|
936
|
+
"sourceHash": "851cc71b74ec904a",
|
|
937
|
+
"ts": "// Set a \"tint\" constant in a constant buffer in the render script:\nconst constants = render.constant_buffer();\nconstants.tint = vmath.vector4(1, 1, 1, 1);\n\n// Then use the constant buffer when drawing a predicate:\nrender.draw(self.my_pred, { constants });\n\n// The constant buffer also supports array values by specifying constants in an array:\nconst constants2 = render.constant_buffer();\nconstants2.light_colors = [];\nconstants2.light_colors[0] = vmath.vector4(1, 0, 0, 1);\nconstants2.light_colors[1] = vmath.vector4(0, 1, 0, 1);\nconstants2.light_colors[2] = vmath.vector4(0, 0, 1, 1);\n\n// You can also create the array by passing the vectors directly:\nconst constants3 = render.constant_buffer();\nconstants3.light_colors = [\n vmath.vector4(1, 0, 0, 1),\n vmath.vector4(0, 1, 0, 1),\n vmath.vector4(0, 0, 1, 1),\n];\n\n// Add more constants to the array\nconstants3.light_colors[3] = vmath.vector4(1, 1, 1, 1);"
|
|
938
|
+
}
|
|
939
|
+
],
|
|
940
|
+
"render.delete_render_target": [
|
|
941
|
+
{
|
|
942
|
+
"sourceHash": "e535502af5d49877",
|
|
943
|
+
"ts": "// How to delete a render target:\nrender.delete_render_target(self.my_render_target);"
|
|
944
|
+
}
|
|
945
|
+
],
|
|
946
|
+
"render.disable_material": [
|
|
947
|
+
{
|
|
948
|
+
"sourceHash": "256ae7b73905f4b2",
|
|
949
|
+
"ts": "// Enable material named \"glow\", then draw my_pred with it.\nrender.enable_material(\"glow\");\nrender.draw(self.my_pred);\nrender.disable_material();"
|
|
950
|
+
}
|
|
951
|
+
],
|
|
952
|
+
"render.disable_state": [
|
|
953
|
+
{
|
|
954
|
+
"sourceHash": "9ec916d3d474ace5",
|
|
955
|
+
"ts": "// Disable face culling when drawing the tile predicate:\nrender.disable_state(graphics.STATE_CULL_FACE);\nrender.draw(self.tile_pred);"
|
|
956
|
+
}
|
|
957
|
+
],
|
|
958
|
+
"render.disable_texture": [
|
|
959
|
+
{
|
|
960
|
+
"sourceHash": "77eefc5b608dd2e6",
|
|
961
|
+
"ts": "export default defineScript({\n update(self, dt) {\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n // done, disable the texture\n render.disable_texture(0);\n },\n});"
|
|
962
|
+
}
|
|
963
|
+
],
|
|
964
|
+
"render.dispatch_compute": [
|
|
965
|
+
{
|
|
966
|
+
"sourceHash": "af76607a05354da7",
|
|
967
|
+
"ts": "export default defineScript({\n init() {\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n };\n return {\n scene_rt: render.render_target({ [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params }),\n };\n },\n\n update(self, dt) {\n render.set_compute(\"bloom\");\n render.enable_texture(0, self.backing_texture);\n render.enable_texture(1, self.scene_rt);\n render.dispatch_compute(128, 128, 1);\n render.set_compute();\n },\n});\n\n// Dispatch a compute program with a constant buffer:\nconst constants = render.constant_buffer();\nconstants.tint = vmath.vector4(1, 1, 1, 1);\nrender.dispatch_compute(32, 32, 32, { constants });"
|
|
968
|
+
}
|
|
969
|
+
],
|
|
970
|
+
"render.draw": [
|
|
971
|
+
{
|
|
972
|
+
"sourceHash": "47232b75e7b74189",
|
|
973
|
+
"ts": "export default defineScript({\n init() {\n // define a predicate matching anything with material tag \"my_tag\"\n return { my_pred: render.predicate([hash(\"my_tag\")]) };\n },\n\n update(self, dt) {\n // draw everything in the my_pred predicate\n render.draw(self.my_pred);\n },\n});\n\n// Draw predicate with constants:\nconst constants = render.constant_buffer();\nconstants.tint = vmath.vector4(1, 1, 1, 1);\nrender.draw(self.my_pred, { constants });\n\n// Draw with predicate and frustum culling (without near+far planes):\nconst frustum = self.proj.mul(self.view);\nrender.draw(self.my_pred, { frustum });\n\n// Draw with predicate and frustum culling (with near+far planes):\nconst frustum2 = self.proj.mul(self.view);\nrender.draw(self.my_pred, { frustum: frustum2, frustum_planes: render.FRUSTUM_PLANES_ALL });"
|
|
974
|
+
}
|
|
975
|
+
],
|
|
976
|
+
"render.draw_debug3d": [
|
|
977
|
+
{
|
|
978
|
+
"sourceHash": "b200f780e2bf16f3",
|
|
979
|
+
"ts": "export default defineScript({\n update(self, dt) {\n // draw debug visualization\n render.draw_debug3d();\n },\n});"
|
|
980
|
+
}
|
|
981
|
+
],
|
|
982
|
+
"render.enable_material": [
|
|
983
|
+
{
|
|
984
|
+
"sourceHash": "256ae7b73905f4b2",
|
|
985
|
+
"ts": "// Enable material named \"glow\", then draw my_pred with it.\nrender.enable_material(\"glow\");\nrender.draw(self.my_pred);\nrender.disable_material();"
|
|
986
|
+
}
|
|
987
|
+
],
|
|
988
|
+
"render.enable_state": [
|
|
989
|
+
{
|
|
990
|
+
"sourceHash": "d08dd567d90c4036",
|
|
991
|
+
"ts": "// Enable stencil test when drawing the gui predicate, then disable it:\nrender.enable_state(graphics.STATE_STENCIL_TEST);\nrender.draw(self.gui_pred);\nrender.disable_state(graphics.STATE_STENCIL_TEST);"
|
|
992
|
+
}
|
|
993
|
+
],
|
|
994
|
+
"render.enable_texture": [
|
|
995
|
+
{
|
|
996
|
+
"sourceHash": "4dd1d2618c062e70",
|
|
997
|
+
"ts": "export default defineScript({\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // disable target\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, self.my_render_target, graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});\n\n// Or enable a render target by resource id:\nexport default defineScript({\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n render.draw(self.my_pred);\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n\n render.enable_texture(0, \"my_rt_resource\", graphics.BUFFER_TYPE_COLOR0_BIT);\n // draw a predicate with the render target available as texture 0 in the predicate\n // material shader.\n render.draw(self.my_pred);\n },\n});\n\n// Or bind a texture handle directly:\nexport default defineScript({\n update(self, dt) {\n // bind a texture to the texture unit 0\n render.enable_texture(0, self.my_texture_handle);\n // bind the same texture to a named sampler\n render.enable_texture(\"my_texture_sampler\", self.my_texture_handle);\n },\n});"
|
|
998
|
+
}
|
|
999
|
+
],
|
|
1000
|
+
"render.get_height": [
|
|
1001
|
+
{
|
|
1002
|
+
"sourceHash": "a23f1ae69eff75c0",
|
|
1003
|
+
"ts": "// Get the height of the window\nconst h = render.get_height();"
|
|
1004
|
+
}
|
|
1005
|
+
],
|
|
1006
|
+
"render.get_render_target_height": [
|
|
1007
|
+
{
|
|
1008
|
+
"sourceHash": "f509a9b954573583",
|
|
1009
|
+
"ts": "// get the height of the render target color buffer\nconst h = render.get_render_target_height(self.target_right, graphics.BUFFER_TYPE_COLOR0_BIT);\n// get the height of a render target resource\nconst w = render.get_render_target_height(\"my_rt_resource\", graphics.BUFFER_TYPE_COLOR0_BIT);"
|
|
1010
|
+
}
|
|
1011
|
+
],
|
|
1012
|
+
"render.get_render_target_width": [
|
|
1013
|
+
{
|
|
1014
|
+
"sourceHash": "25c6d828a4ae3706",
|
|
1015
|
+
"ts": "// get the width of the render target color buffer\nconst w = render.get_render_target_width(self.target_right, graphics.BUFFER_TYPE_COLOR0_BIT);\n// get the width of a render target resource\nconst w2 = render.get_render_target_width(\"my_rt_resource\", graphics.BUFFER_TYPE_COLOR0_BIT);"
|
|
1016
|
+
}
|
|
1017
|
+
],
|
|
1018
|
+
"render.get_width": [
|
|
1019
|
+
{
|
|
1020
|
+
"sourceHash": "8d7965e500d69d03",
|
|
1021
|
+
"ts": "// Get the width of the window.\nconst w = render.get_width();"
|
|
1022
|
+
}
|
|
1023
|
+
],
|
|
1024
|
+
"render.get_window_height": [
|
|
1025
|
+
{
|
|
1026
|
+
"sourceHash": "0afddc76d47d533f",
|
|
1027
|
+
"ts": "// Get the actual height of the window\nconst h = render.get_window_height();"
|
|
1028
|
+
}
|
|
1029
|
+
],
|
|
1030
|
+
"render.get_window_width": [
|
|
1031
|
+
{
|
|
1032
|
+
"sourceHash": "034929ff14cf8dac",
|
|
1033
|
+
"ts": "// Get the actual width of the window\nconst w = render.get_window_width();"
|
|
1034
|
+
}
|
|
1035
|
+
],
|
|
1036
|
+
"render.predicate": [
|
|
1037
|
+
{
|
|
1038
|
+
"sourceHash": "886d641eaa12199e",
|
|
1039
|
+
"ts": "// Create a new render predicate containing all visual objects that\n// have a material with material tags \"opaque\" AND \"smoke\".\nconst p = render.predicate([hash(\"opaque\"), hash(\"smoke\")]);"
|
|
1040
|
+
}
|
|
1041
|
+
],
|
|
1042
|
+
"render.render_target": [
|
|
1043
|
+
{
|
|
1044
|
+
"sourceHash": "608b59338c18571b",
|
|
1045
|
+
"ts": "// How to create a new render target and draw to it:\nexport default defineScript({\n init() {\n // render target buffer parameters\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const depth_params = {\n format: graphics.TEXTURE_FORMAT_DEPTH,\n width: render.get_window_width(),\n height: render.get_window_height(),\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params,\n [graphics.BUFFER_TYPE_DEPTH_BIT]: depth_params,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});\n\n// How to create a render target with multiple outputs:\nexport default defineScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.enable_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
"sourceHash": "766fbfcc7bc21b4b",
|
|
1049
|
+
"ts": "// How to create a new render target and draw to it:\nexport default defineScript({\n init() {\n // render target buffer parameters\n const color_params = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const depth_params = {\n format: graphics.TEXTURE_FORMAT_DEPTH,\n width: render.get_window_width(),\n height: render.get_window_height(),\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params,\n [graphics.BUFFER_TYPE_DEPTH_BIT]: depth_params,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.set_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});\n\n// How to create a render target with multiple outputs:\nexport default defineScript({\n init() {\n // render target buffer parameters\n const color_params_rgba = {\n format: graphics.TEXTURE_FORMAT_RGBA,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n const color_params_float = {\n format: graphics.TEXTURE_FORMAT_RG32F,\n width: render.get_window_width(),\n height: render.get_window_height(),\n min_filter: graphics.TEXTURE_FILTER_LINEAR,\n mag_filter: graphics.TEXTURE_FILTER_LINEAR,\n u_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n v_wrap: graphics.TEXTURE_WRAP_CLAMP_TO_EDGE,\n };\n\n // Create a render target with three color attachments\n // Note: No depth buffer is attached here\n return {\n my_render_target: render.render_target({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR1_BIT]: color_params_rgba,\n [graphics.BUFFER_TYPE_COLOR2_BIT]: color_params_float,\n }),\n };\n },\n\n update(self, dt) {\n // enable target so all drawing is done to it\n render.enable_render_target(self.my_render_target);\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n },\n});"
|
|
1050
|
+
}
|
|
1051
|
+
],
|
|
1052
|
+
"render.set_blend_equation_separate": [
|
|
1053
|
+
{
|
|
1054
|
+
"sourceHash": "5d39d5b048d13896",
|
|
1055
|
+
"ts": "render.set_blend_equation_separate(graphics.BLEND_EQUATION_ADD, graphics.BLEND_EQUATION_REVERSE_SUBTRACT);"
|
|
1056
|
+
}
|
|
1057
|
+
],
|
|
1058
|
+
"render.set_blend_func": [
|
|
1059
|
+
{
|
|
1060
|
+
"sourceHash": "3c8b3570a329836b",
|
|
1061
|
+
"ts": "// Set the blend func to the most common one:\nrender.set_blend_func(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);"
|
|
1062
|
+
}
|
|
1063
|
+
],
|
|
1064
|
+
"render.set_blend_func_separate": [
|
|
1065
|
+
{
|
|
1066
|
+
"sourceHash": "9c7c4c926dd7608f",
|
|
1067
|
+
"ts": "render.set_blend_func_separate(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, graphics.BLEND_FACTOR_ONE, graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);"
|
|
1068
|
+
}
|
|
1069
|
+
],
|
|
1070
|
+
"render.set_camera": [
|
|
1071
|
+
{
|
|
1072
|
+
"sourceHash": "6ee012d07a0487a6",
|
|
1073
|
+
"ts": "// Set the current camera to be used for rendering\nrender.set_camera(\"main:/my_go#camera\");\nrender.draw(self.my_pred);\nrender.set_camera(undefined);\n\n// Use the camera frustum for frustum culling together with a specific frustum plane option for the draw command\n// The camera frustum will take precedence over the frustum plane option in render.draw\nrender.set_camera(\"main:/my_go#camera\", { use_frustum: true });\n// However, we can still customize the frustum planes regardless of the camera option!\nrender.draw(self.my_pred, { frustum_planes: render.FRUSTUM_PLANES_ALL });\nrender.set_camera();"
|
|
1074
|
+
}
|
|
1075
|
+
],
|
|
1076
|
+
"render.set_color_mask": [
|
|
1077
|
+
{
|
|
1078
|
+
"sourceHash": "760910f9fe70ace7",
|
|
1079
|
+
"ts": "// alpha cannot be written to frame buffer\nrender.set_color_mask(true, true, true, false);"
|
|
1080
|
+
}
|
|
1081
|
+
],
|
|
1082
|
+
"render.set_compute": [
|
|
1083
|
+
{
|
|
1084
|
+
"sourceHash": "5e76b88c05d9f3f7",
|
|
1085
|
+
"ts": "// Enable compute program named \"fractals\", then dispatch it.\nrender.set_compute(\"fractals\");\nrender.enable_texture(0, self.backing_texture);\nrender.dispatch_compute(128, 128, 1);\nrender.set_compute();"
|
|
1086
|
+
}
|
|
1087
|
+
],
|
|
1088
|
+
"render.set_cull_face": [
|
|
1089
|
+
{
|
|
1090
|
+
"sourceHash": "3ac86c74ed257860",
|
|
1091
|
+
"ts": "// How to enable polygon culling and set front face culling:\nrender.enable_state(graphics.STATE_CULL_FACE);\nrender.set_cull_face(graphics.FACE_TYPE_FRONT);"
|
|
1092
|
+
}
|
|
1093
|
+
],
|
|
1094
|
+
"render.set_depth_func": [
|
|
1095
|
+
{
|
|
1096
|
+
"sourceHash": "3b3f38f0739a92b6",
|
|
1097
|
+
"ts": "// Enable depth test and set the depth test function to \"not equal\".\nrender.enable_state(graphics.STATE_DEPTH_TEST);\nrender.set_depth_func(graphics.COMPARE_FUNC_NOTEQUAL);"
|
|
1098
|
+
}
|
|
1099
|
+
],
|
|
1100
|
+
"render.set_depth_mask": [
|
|
1101
|
+
{
|
|
1102
|
+
"sourceHash": "6713731143e36de2",
|
|
1103
|
+
"ts": "// How to turn off writing to the depth buffer:\nrender.set_depth_mask(false);"
|
|
1104
|
+
}
|
|
1105
|
+
],
|
|
1106
|
+
"render.set_listener": [
|
|
1107
|
+
{
|
|
1108
|
+
"sourceHash": "6fc340897eeb1ab9",
|
|
1109
|
+
"ts": "// Set listener and handle render context events.\n// custom.render_script\nexport default defineScript({\n init() {\n render.set_listener((self, event_type) => {\n if (event_type === render.CONTEXT_EVENT_CONTEXT_LOST) {\n // Some stuff when rendering context is lost\n } else if (event_type === render.CONTEXT_EVENT_CONTEXT_RESTORED) {\n // Start reload resources, reload game, etc.\n }\n });\n },\n});"
|
|
1110
|
+
}
|
|
1111
|
+
],
|
|
1112
|
+
"render.set_polygon_offset": [
|
|
1113
|
+
{
|
|
1114
|
+
"sourceHash": "c8aa9b10abbb6154",
|
|
1115
|
+
"ts": "render.enable_state(graphics.STATE_POLYGON_OFFSET_FILL);\nrender.set_polygon_offset(1.0, 1.0);"
|
|
1116
|
+
}
|
|
1117
|
+
],
|
|
1118
|
+
"render.set_projection": [
|
|
1119
|
+
{
|
|
1120
|
+
"sourceHash": "b0155866d7b9eae0",
|
|
1121
|
+
"ts": "// How to set the projection to orthographic with world origo at lower left,\n// width and height as set in project settings and depth (z) between -1 and 1:\nrender.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1));"
|
|
1122
|
+
}
|
|
1123
|
+
],
|
|
1124
|
+
"render.set_render_target": [
|
|
1125
|
+
{
|
|
1126
|
+
"sourceHash": "b30691f486beb1fa",
|
|
1127
|
+
"ts": "// How to set a render target and draw to it and then switch back to the default render target\n// The render target defines the depth/stencil buffers as transient, when set_render_target is called the next time the buffers may be invalidated and allow for optimisations depending on driver support\nexport default defineScript({\n update(self, dt) {\n // set render target so all drawing is done to it\n render.set_render_target(self.my_render_target, {\n transient: [graphics.BUFFER_TYPE_DEPTH_BIT, graphics.BUFFER_TYPE_STENCIL_BIT],\n });\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // set default render target. This also invalidates the depth and stencil buffers of the current target (self.my_render_target)\n // which can be an optimisation on some hardware\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});\n\n// Or set the render target by a render target resource identifier:\nexport default defineScript({\n update(self, dt) {\n render.set_render_target(\"my_rt_resource\");\n\n // draw a predicate to the render target\n render.draw(self.my_pred);\n\n // reset the render target to the default backbuffer\n render.set_render_target(render.RENDER_TARGET_DEFAULT);\n },\n});"
|
|
1128
|
+
}
|
|
1129
|
+
],
|
|
1130
|
+
"render.set_render_target_size": [
|
|
1131
|
+
{
|
|
1132
|
+
"sourceHash": "00274352e6327274",
|
|
1133
|
+
"ts": "// Resize render targets to the current window size:\nrender.set_render_target_size(self.my_render_target, render.get_window_width(), render.get_window_height());\nrender.set_render_target_size(\"my_rt_resource\", render.get_window_width(), render.get_window_height());"
|
|
1134
|
+
}
|
|
1135
|
+
],
|
|
1136
|
+
"render.set_stencil_func": [
|
|
1137
|
+
{
|
|
1138
|
+
"sourceHash": "855e83671907ce10",
|
|
1139
|
+
"ts": "// let only 0's pass the stencil test\nrender.set_stencil_func(graphics.COMPARE_FUNC_EQUAL, 0, 1);"
|
|
1140
|
+
}
|
|
1141
|
+
],
|
|
1142
|
+
"render.set_stencil_mask": [
|
|
1143
|
+
{
|
|
1144
|
+
"sourceHash": "8f3e5667355445c5",
|
|
1145
|
+
"ts": "// set the stencil mask to all 1:s\nrender.set_stencil_mask(0xff);"
|
|
1146
|
+
}
|
|
1147
|
+
],
|
|
1148
|
+
"render.set_stencil_op": [
|
|
1149
|
+
{
|
|
1150
|
+
"sourceHash": "33e5e22efb9275ea",
|
|
1151
|
+
"ts": "// Set the stencil function to never pass and operator to always draw 1's\n// on test fail.\nrender.set_stencil_func(graphics.COMPARE_FUNC_NEVER, 1, 0xFF);\n// always draw 1's on test fail\nrender.set_stencil_op(graphics.STENCIL_OP_REPLACE, graphics.STENCIL_OP_KEEP, graphics.STENCIL_OP_KEEP);"
|
|
1152
|
+
}
|
|
1153
|
+
],
|
|
1154
|
+
"render.set_view": [
|
|
1155
|
+
{
|
|
1156
|
+
"sourceHash": "7a30b4955abb3844",
|
|
1157
|
+
"ts": "// How to set the view and projection matrices according to\n// the values supplied by a camera.\nexport default defineScript({\n init() {\n return {\n view: vmath.matrix4(),\n projection: vmath.matrix4(),\n };\n },\n\n update(self, dt) {\n // set the view to the stored view value\n render.set_view(self.view);\n // now we can draw with this view\n },\n\n on_message(self, message_id, message) {\n if (message_id === hash(\"set_view_projection\")) {\n // camera view and projection arrives here.\n self.view = message.view;\n self.projection = message.projection;\n }\n },\n});"
|
|
1158
|
+
}
|
|
1159
|
+
],
|
|
1160
|
+
"render.set_viewport": [
|
|
1161
|
+
{
|
|
1162
|
+
"sourceHash": "2fb80af31ed168b8",
|
|
1163
|
+
"ts": "// Set the viewport to the window dimensions.\nrender.set_viewport(0, 0, render.get_window_width(), render.get_window_height());"
|
|
1164
|
+
}
|
|
1165
|
+
],
|
|
1166
|
+
"resource.atlas": [
|
|
1167
|
+
{
|
|
1168
|
+
"sourceHash": "ee6a5c4c09121554",
|
|
1169
|
+
"ts": "// Load an atlas and set it to a sprite:\ngo.property(\"my_atlas\", resource.atlas(\"/atlas.atlas\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#sprite\", \"image\", self.my_atlas);\n },\n});\n\n// Load an atlas and set it to a gui:\ngo.property(\"my_atlas\", resource.atlas(\"/atlas.atlas\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#gui\", \"textures\", self.my_atlas, { key: \"my_atlas\" });\n },\n});"
|
|
1170
|
+
}
|
|
1171
|
+
],
|
|
1172
|
+
"resource.buffer": [
|
|
1173
|
+
{
|
|
1174
|
+
"sourceHash": "4353a4d474ea70b6",
|
|
1175
|
+
"ts": "// Set a unique buffer it to a sprite:\ngo.property(\"my_buffer\", resource.buffer(\"/cube.buffer\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#mesh\", \"vertices\", self.my_buffer);\n },\n});"
|
|
1176
|
+
}
|
|
1177
|
+
],
|
|
1178
|
+
"resource.create_atlas": [
|
|
1179
|
+
{
|
|
1180
|
+
"sourceHash": "987cf3d09a4ce250",
|
|
1181
|
+
"ts": "// Create a backing texture and an atlas\nexport default defineScript({\n init() {\n // create an empty texture\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA,\n };\n const my_texture_id = resource.create_texture(\"/my_texture.texturec\", tparams);\n\n // optionally use resource.set_texture to upload data to texture\n\n // create an atlas with one animation and one square geometry\n // note that the function doesn't support hashes for the texture,\n // you need to use a string for the texture path here aswell\n const aparams = {\n texture: \"/my_texture.texturec\",\n animations: [\n {\n id: \"my_animation\",\n width: 128,\n height: 128,\n frames: [1],\n },\n ],\n geometries: [\n {\n id: \"idle0\",\n width: 128,\n height: 128,\n pivot_x: 0.5,\n pivot_y: 0.5,\n vertices: [0, 0, 0, 128, 128, 128, 128, 0],\n uvs: [0, 0, 0, 128, 128, 128, 128, 0],\n indices: [0, 1, 2, 0, 2, 3],\n },\n ],\n };\n const my_atlas_id = resource.create_atlas(\"/my_atlas.texturesetc\", aparams);\n\n // assign the atlas to the 'sprite' component on the same go\n go.set(\"#sprite\", \"image\", my_atlas_id);\n },\n});"
|
|
1182
|
+
}
|
|
1183
|
+
],
|
|
1184
|
+
"resource.create_buffer": [
|
|
1185
|
+
{
|
|
1186
|
+
"sourceHash": "436c1c10688cba69",
|
|
1187
|
+
"ts": "// Create a buffer object and bind it to a buffer resource\nexport default defineScript({\n init() {\n const size = 1;\n const positions = [\n // triangle 1\n size, size, 0,\n -size, -size, 0,\n size, -size, 0,\n // triangle 2\n size, size, 0,\n -size, size, 0,\n -size, -size, 0,\n ];\n\n const buffer_handle = buffer.create(positions.length, [\n {\n name: hash(\"position\"),\n type: buffer.VALUE_TYPE_FLOAT32,\n count: 3,\n },\n ]);\n\n const stream = buffer.get_stream(buffer_handle, hash(\"position\"));\n\n // transfer vertex data to buffer\n for (let k = 0; k < positions.length; k++) {\n stream[k] = positions[k];\n }\n\n const my_buffer = resource.create_buffer(\"/my_buffer.bufferc\", { buffer: buffer_handle });\n go.set(\"/go#mesh\", \"vertices\", my_buffer);\n },\n});\n\n// Create a buffer resource from existing resource\nexport default defineScript({\n init() {\n const res = resource.get_buffer(\"/my_buffer_path.bufferc\");\n // create a cloned buffer resource from another resource buffer\n const buf = resource.create_buffer(\"/my_cloned_buffer.bufferc\", { buffer: res });\n // assign cloned buffer to a mesh component\n go.set(\"/go#mesh\", \"vertices\", buf);\n },\n});"
|
|
1188
|
+
}
|
|
1189
|
+
],
|
|
1190
|
+
"resource.create_sound_data": [
|
|
1191
|
+
{
|
|
1192
|
+
"sourceHash": "19e6f6ab7a317fa1",
|
|
1193
|
+
"ts": "export default defineScript({\n init() {\n // create a new sound resource, given the initial chunk of the file\n const relative_path = \"/a/unique/resource/name.oggc\";\n const hash = resource.create_sound_data(relative_path, { data, filesize, partial: true });\n go.set(\"#music\", \"sound\", hash); // override the previous sound resource\n sound.play(\"#music\"); // start the playing\n },\n});"
|
|
1194
|
+
}
|
|
1195
|
+
],
|
|
1196
|
+
"resource.create_texture": [
|
|
1197
|
+
{
|
|
1198
|
+
"sourceHash": "f510168083ffdd30",
|
|
1199
|
+
"ts": "// How to create an 128x128 RGBA texture resource and assign it to a model\nexport default defineScript({\n init() {\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA,\n };\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams);\n go.set(\"#model\", \"texture0\", my_texture_id);\n },\n});\n\n// How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object\nexport default defineScript({\n init() {\n // Create a new buffer with 4 components and FLOAT32 type\n const tbuffer = buffer.create(128 * 128, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // Fill the buffer stream with some float values\n for (let y = 0; y < 128; y++) {\n for (let x = 0; x < 128; x++) {\n const index = y * 128 * 4 + x * 4;\n tstream[index + 0] = 999.0;\n tstream[index + 1] = -1.0;\n tstream[index + 2] = 0.5;\n tstream[index + 3] = 1.0;\n }\n }\n\n // Create a 2D Texture with a RGBA23F format\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n };\n\n // Note that we pass the buffer as the last argument here!\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams, tbuffer);\n\n // assign the texture to a model\n go.set(\"#model\", \"texture0\", my_texture_id);\n },\n});\n\n// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 32,\n height: 32,\n depth: 32,\n format: resource.TEXTURE_FORMAT_RGBA32F,\n flags: resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,\n });\n\n // pass the backing texture to the render script\n msg.post(\"@render:\", \"add_textures\", [t_volume]);\n },\n});\n\n// How to create 512x512 texture array with 5 pages.\nconst new_tex = resource.create_texture(\"/runtime/example_array.texturec\", {\n type: graphics.TEXTURE_TYPE_2D_ARRAY,\n width: 512,\n height: 512,\n page_count: 5,\n format: graphics.TEXTURE_FORMAT_RGB,\n});"
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1202
|
+
"sourceHash": "41e0481ae55c393d",
|
|
1203
|
+
"ts": "// How to create an 128x128 RGBA texture resource and assign it to a model\nexport default defineScript({\n init() {\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA,\n };\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams);\n go.set(\"#model\", \"texture0\", my_texture_id);\n },\n});\n\n// How to create an 128x128 floating point texture (RGBA32F) resource from a buffer object\nexport default defineScript({\n init() {\n // Create a new buffer with 4 components and FLOAT32 type\n const tbuffer = buffer.create(128 * 128, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // Fill the buffer stream with some float values\n for (let y = 0; y < 128; y++) {\n for (let x = 0; x < 128; x++) {\n const index = y * 128 * 4 + x * 4;\n tstream[index + 0] = 999.0;\n tstream[index + 1] = -1.0;\n tstream[index + 2] = 0.5;\n tstream[index + 3] = 1.0;\n }\n }\n\n // Create a 2D Texture with a RGBA23F format\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA32F,\n };\n\n // Note that we pass the buffer as the last argument here!\n const my_texture_id = resource.create_texture(\"/my_custom_texture.texturec\", tparams, tbuffer);\n\n // assign the texture to a model\n go.set(\"#model\", \"texture0\", my_texture_id);\n },\n});\n\n// How to create a 32x32x32 floating point 3D texture that can be used to generate volumetric data in a compute shader\nexport default defineScript({\n init() {\n const t_volume = resource.create_texture(\"/my_backing_texture.texturec\", {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 32,\n height: 32,\n depth: 32,\n format: resource.TEXTURE_FORMAT_RGBA32F,\n flags: resource.TEXTURE_USAGE_FLAG_STORAGE + resource.TEXTURE_USAGE_FLAG_SAMPLE,\n });\n\n // pass the backing texture to the render script\n msg.post(\"@render:\", \"add_textures\", [t_volume]);\n },\n});\n\n// How to create 512x512 texture array with 5 pages.\nconst new_tex = resource.create_texture(\"/runtime/example_array.texturec\", {\n type: graphics.TEXTURE_TYPE_2D_ARRAY,\n width: 512,\n height: 512,\n page_count: 5,\n format: graphics.TEXTURE_FORMAT_RGB,\n});"
|
|
1204
|
+
}
|
|
1205
|
+
],
|
|
1206
|
+
"resource.create_texture_async": [
|
|
1207
|
+
{
|
|
1208
|
+
"sourceHash": "b90223f19d598eaa",
|
|
1209
|
+
"ts": "// Create a texture resource asyncronously with a buffer and a callback\nfunction callback(self, request_id, resource) {\n // The resource has been updated with a new texture,\n // so we can update other systems with the new handle,\n // or update components to use the resource if we want\n const tinfo = resource.get_texture_info(resource);\n msg.post(\"@render:\", \"set_backing_texture\", tinfo.handle);\n}\n\nexport default defineScript({\n init() {\n // Create a texture resource async\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA,\n };\n\n // Create a new buffer with 4 components\n const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // Fill the buffer stream with some float values\n for (let y = 0; y < tparams.width; y++) {\n for (let x = 0; x < tparams.height; x++) {\n const index = y * 128 * 4 + x * 4;\n tstream[index + 0] = 255;\n tstream[index + 1] = 0;\n tstream[index + 2] = 255;\n tstream[index + 3] = 255;\n }\n }\n // create the texture\n const [tpath, request_id] = resource.create_texture_async(\"/my_texture.texturec\", tparams, tbuffer, callback);\n // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture\n // that will be removed once the new texture has been updated\n go.set(\"#model\", \"texture0\", tpath);\n },\n});\n\n// Create a texture resource asyncronously without a callback\nexport default defineScript({\n init() {\n // Create a texture resource async\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA,\n };\n\n // Create a new buffer with 4 components\n const tbuffer = buffer.create(tparams.width * tparams.height, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_UINT8, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // Fill the buffer stream with some float values\n for (let y = 0; y < tparams.width; y++) {\n for (let x = 0; x < tparams.height; x++) {\n const index = y * 128 * 4 + x * 4;\n tstream[index + 0] = 255;\n tstream[index + 1] = 0;\n tstream[index + 2] = 255;\n tstream[index + 3] = 255;\n }\n }\n // create the texture\n const [tpath, request_id] = resource.create_texture_async(\"/my_texture.texturec\", tparams, tbuffer);\n // at this point you can use the resource as-is, but note that the texture will be a blank 1x1 texture\n // that will be removed once the new texture has been updated\n go.set(\"#model\", \"texture0\", tpath);\n },\n});"
|
|
1210
|
+
}
|
|
1211
|
+
],
|
|
1212
|
+
"resource.font": [
|
|
1213
|
+
{
|
|
1214
|
+
"sourceHash": "f6d4ca24e4f87bfe",
|
|
1215
|
+
"ts": "// Load a font and set it to a label:\ngo.property(\"my_font\", resource.font(\"/font.font\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#label\", \"font\", self.my_font);\n },\n});\n\n// Load a font and set it to a gui:\ngo.property(\"my_font\", resource.font(\"/font.font\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#gui\", \"fonts\", self.my_font, { key: \"my_font\" });\n },\n});"
|
|
1216
|
+
}
|
|
1217
|
+
],
|
|
1218
|
+
"resource.get_buffer": [
|
|
1219
|
+
{
|
|
1220
|
+
"sourceHash": "ed7d361c7f5d2e35",
|
|
1221
|
+
"ts": "// How to get the data from a buffer\nexport default defineScript({\n init() {\n const res_path = go.get(\"#mesh\", \"vertices\");\n const buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n for (let i = 0; i < stream_positions.length; i++) {\n print(i, stream_positions[i]);\n }\n },\n});"
|
|
1222
|
+
}
|
|
1223
|
+
],
|
|
1224
|
+
"resource.get_render_target_info": [
|
|
1225
|
+
{
|
|
1226
|
+
"sourceHash": "5e526c539ed8ae25",
|
|
1227
|
+
"ts": "// Get the metadata from a render target resource\nexport default defineScript({\n init() {\n const info = resource.get_render_target_info(\"/my_render_target.render_targetc\");\n // the info table contains meta data about all the render target attachments\n // so it's not necessary to use resource.get_texture here, but we do it here\n // just to show that it's possible:\n const info_attachment_1 = resource.get_texture_info(info.attachments[0].handle);\n },\n});\n\n// Get a texture attachment from a render target and set it on a model component\nexport default defineScript({\n init() {\n const info = resource.get_render_target_info(\"/my_render_target.render_targetc\");\n const attachment = info.attachments[0].texture;\n // you can also get texture info from the 'texture' field, since it's a resource hash\n const texture_info = resource.get_texture_info(attachment);\n go.set(\"#model\", \"texture0\", attachment);\n },\n});"
|
|
1228
|
+
}
|
|
1229
|
+
],
|
|
1230
|
+
"resource.get_text_metrics": [
|
|
1231
|
+
{
|
|
1232
|
+
"sourceHash": "d63156dd59513358",
|
|
1233
|
+
"ts": "export default defineScript({\n init() {\n const font = go.get(\"#label\", \"font\");\n const metrics = resource.get_text_metrics(font, \"The quick brown fox\\n jumps over the lazy dog\");\n pprint(metrics);\n },\n});"
|
|
1234
|
+
}
|
|
1235
|
+
],
|
|
1236
|
+
"resource.get_texture_info": [
|
|
1237
|
+
{
|
|
1238
|
+
"sourceHash": "4164f100ea5a8c15",
|
|
1239
|
+
"ts": "// Create a new texture and get the metadata from it\nexport default defineScript({\n init() {\n // create an empty texture\n const tparams = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGBA,\n };\n\n const my_texture_path = resource.create_texture(\"/my_texture.texturec\", tparams);\n const my_texture_info = resource.get_texture_info(my_texture_path);\n\n // my_texture_info now contains\n // {\n // handle = <the-numeric-handle>,\n // width = 128,\n // height = 128,\n // depth = 1\n // mipmaps = 1,\n // page_count = 1,\n // type = graphics.TEXTURE_TYPE_2D,\n // flags = graphics.TEXTURE_USAGE_FLAG_SAMPLE\n // }\n },\n});\n\n// Get the meta data from an atlas resource\nexport default defineScript({\n init() {\n const my_atlas_info = resource.get_atlas(\"/my_atlas.a.texturesetc\");\n const my_texture_info = resource.get_texture_info(my_atlas_info.texture);\n\n // my_texture_info now contains the information about the texture that is backing the atlas\n },\n});"
|
|
1240
|
+
}
|
|
1241
|
+
],
|
|
1242
|
+
"resource.load": [
|
|
1243
|
+
{
|
|
1244
|
+
"sourceHash": "051230427173b08a",
|
|
1245
|
+
"ts": "// read custom resource data into buffer\nconst buffer = resource.load(\"/resources/datafile\");\n\n// In order for the engine to include custom resources in the build process, you\n// need to specify them in the \"game.project\" settings file:\n// [project]\n// title = My project\n// version = 0.1\n// custom_resources = resources/,assets/level_data.json"
|
|
1246
|
+
}
|
|
1247
|
+
],
|
|
1248
|
+
"resource.material": [
|
|
1249
|
+
{
|
|
1250
|
+
"sourceHash": "5bc0271405b04027",
|
|
1251
|
+
"ts": "// Load a material and set it to a sprite:\ngo.property(\"my_material\", resource.material(\"/material.material\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#sprite\", \"material\", self.my_material);\n },\n});\n\n// Load a material resource and update a named material with the resource:\ngo.property(\"my_material\", resource.material(\"/material.material\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#gui\", \"materials\", self.my_material, { key: \"my_material\" });\n },\n});"
|
|
1252
|
+
}
|
|
1253
|
+
],
|
|
1254
|
+
"resource.render_target": [
|
|
1255
|
+
{
|
|
1256
|
+
"sourceHash": "87231742204d2351",
|
|
1257
|
+
"ts": "// Set a render target color attachment as a model texture:\ngo.property(\"my_render_target\", resource.render_target(\"/rt.render_target\"));\n\nexport default defineScript({\n init(self) {\n const rt_info = resource.get_render_target_info(self.my_render_target);\n go.set(\"#model\", \"texture0\", rt_info.attachments[0].texture);\n },\n});"
|
|
1258
|
+
}
|
|
1259
|
+
],
|
|
1260
|
+
"resource.set": [
|
|
1261
|
+
{
|
|
1262
|
+
"sourceHash": "fd3445f93ecdd85e",
|
|
1263
|
+
"ts": "// Assuming the folder \"/res\" is added to the project custom resources:\n// load a texture resource and set it on a sprite\nconst buffer = resource.load(\"/res/new.texturec\");\nresource.set(go.get(\"#sprite\", \"texture0\"), buffer);"
|
|
1264
|
+
}
|
|
1265
|
+
],
|
|
1266
|
+
"resource.set_atlas": [
|
|
1267
|
+
{
|
|
1268
|
+
"sourceHash": "349576ce8a915179",
|
|
1269
|
+
"ts": "// Add a new animation to an existing atlas\nexport default defineScript({\n init() {\n const data = resource.get_atlas(\"/main/my_atlas.a.texturesetc\");\n const my_animation = {\n id: \"my_new_animation\",\n width: 128,\n height: 128,\n frame_start: 1,\n frame_end: 6,\n playback: go.PLAYBACK_LOOP_PINGPONG,\n fps: 8,\n };\n data.animations.push(my_animation);\n resource.set_atlas(\"/main/my_atlas.a.texturesetc\", data);\n },\n});\n\n// Sets atlas data for a 256x256 texture with a single animation being rendered as a quad\nexport default defineScript({\n init() {\n const params = {\n texture: \"/main/my_256x256_texture.texturec\",\n animations: [\n {\n id: \"my_animation\",\n width: 256,\n height: 256,\n frames: [1],\n },\n ],\n geometries: [\n {\n vertices: [0, 0, 0, 256, 256, 256, 256, 0],\n uvs: [0, 0, 0, 256, 256, 256, 256, 0],\n indices: [0, 1, 2, 0, 2, 3],\n },\n ],\n };\n resource.set_atlas(\"/main/test.a.texturesetc\", params);\n },\n});"
|
|
1270
|
+
}
|
|
1271
|
+
],
|
|
1272
|
+
"resource.set_buffer": [
|
|
1273
|
+
{
|
|
1274
|
+
"sourceHash": "a52fd8ac7453f601",
|
|
1275
|
+
"ts": "// How to set the data from a buffer\nfunction fill_stream(stream, verts) {\n verts.forEach((value, key) => {\n stream[key] = verts[key];\n });\n}\n\nexport default defineScript({\n init() {\n const res_path = go.get(\"#mesh\", \"vertices\");\n\n const positions = [\n 1, -1, 0,\n 1, 1, 0,\n -1, -1, 0,\n ];\n\n const num_verts = positions.length / 3;\n\n // create a new buffer\n let buf = buffer.create(num_verts, [{ name: hash(\"position\"), type: buffer.VALUE_TYPE_FLOAT32, count: 3 }]);\n\n buf = resource.get_buffer(res_path);\n const stream_positions = buffer.get_stream(buf, \"position\");\n\n fill_stream(stream_positions, positions);\n\n resource.set_buffer(res_path, buf);\n },\n});"
|
|
1276
|
+
}
|
|
1277
|
+
],
|
|
1278
|
+
"resource.set_texture": [
|
|
1279
|
+
{
|
|
1280
|
+
"sourceHash": "1f7a5108992a12f0",
|
|
1281
|
+
"ts": "// How to set all pixels of an atlas\nexport default defineScript({\n init(self) {\n self.height = 128;\n self.width = 128;\n self.buffer = buffer.create(self.width * self.height, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n self.stream = buffer.get_stream(self.buffer, hash(\"rgb\"));\n\n for (let y = 0; y < self.height; y++) {\n for (let x = 0; x < self.width; x++) {\n const index = y * self.width * 3 + x * 3;\n self.stream[index + 0] = 0xff;\n self.stream[index + 1] = 0x80;\n self.stream[index + 2] = 0x10;\n }\n }\n\n const resource_path = go.get(\"#model\", \"texture0\");\n const args = { width: self.width, height: self.height, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };\n resource.set_texture(resource_path, args, self.buffer);\n },\n});\n\n// How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.\nexport default defineScript({\n init(self) {\n self.x = 16;\n self.y = 16;\n self.height = 128 - self.x * 2;\n self.width = 128 - self.y * 2;\n self.buffer = buffer.create(self.width * self.height, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n self.stream = buffer.get_stream(self.buffer, hash(\"rgb\"));\n\n for (let y = 0; y < self.height; y++) {\n for (let x = 0; x < self.width; x++) {\n const index = y * self.width * 3 + x * 3;\n self.stream[index + 0] = 0xff;\n self.stream[index + 1] = 0x80;\n self.stream[index + 2] = 0x10;\n }\n }\n\n const resource_path = go.get(\"#model\", \"texture0\");\n const args = { width: self.width, height: self.height, x: self.x, y: self.y, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };\n resource.set_texture(resource_path, args, self.buffer);\n },\n});\n\n// Update a texture from a buffer resource\ngo.property(\"my_buffer\", resource.buffer(\"/my_default_buffer.buffer\"));\n\nexport default defineScript({\n init(self) {\n const resource_path = go.get(\"#model\", \"texture0\");\n // the \"my_buffer\" resource is expected to hold 128 * 128 * 3 bytes!\n const args = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGB,\n };\n // Note that the extra resource.get_buffer call is a requirement here\n // since the \"self.my_buffer\" is just pointing to a buffer resource path\n // and not an actual buffer object or buffer resource.\n resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer));\n },\n});\n\n// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format: resource.TEXTURE_FORMAT_RGBA32F,\n };\n\n // This expects that the texture resource \"/my_3d_texture.texturec\" already exists\n // and is a 3D texture resource. To create a dynamic 3D texture resource\n // use the \"resource.create_texture\" function.\n resource.set_texture(\"/my_3d_texture.texturec\", t_args, tbuffer);\n },\n});\n\n// Update texture 2nd array page with loaded texture from png\n// new_tex is resource handle of texture which was created via resource.create_resource\nconst tex_path = \"/bundle_resources/page_02.png\";\nconst [data] = sys.load_resource(tex_path);\nconst buf = image.load_buffer(data);\nresource.set_texture(\n new_tex,\n {\n type: graphics.TEXTURE_TYPE_2D_ARRAY,\n width: buf.width,\n height: buf.height,\n page: 1,\n format: graphics.TEXTURE_FORMAT_RGB,\n },\n buf.buffer,\n);\ngo.set(\"#mesh\", \"texture0\", new_tex);"
|
|
1282
|
+
},
|
|
1283
|
+
{
|
|
1284
|
+
"sourceHash": "48a7f4c2c8433aed",
|
|
1285
|
+
"ts": "// How to set all pixels of an atlas\nexport default defineScript({\n init(self) {\n self.height = 128;\n self.width = 128;\n self.buffer = buffer.create(self.width * self.height, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n self.stream = buffer.get_stream(self.buffer, hash(\"rgb\"));\n\n for (let y = 0; y < self.height; y++) {\n for (let x = 0; x < self.width; x++) {\n const index = y * self.width * 3 + x * 3;\n self.stream[index + 0] = 0xff;\n self.stream[index + 1] = 0x80;\n self.stream[index + 2] = 0x10;\n }\n }\n\n const resource_path = go.get(\"#model\", \"texture0\");\n const args = { width: self.width, height: self.height, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };\n resource.set_texture(resource_path, args, self.buffer);\n },\n});\n\n// How to update a specific region of an atlas by using the x,y values. Assumes the already set atlas is a 128x128 texture.\nexport default defineScript({\n init(self) {\n self.x = 16;\n self.y = 16;\n self.height = 128 - self.x * 2;\n self.width = 128 - self.y * 2;\n self.buffer = buffer.create(self.width * self.height, [{ name: hash(\"rgb\"), type: buffer.VALUE_TYPE_UINT8, count: 3 }]);\n self.stream = buffer.get_stream(self.buffer, hash(\"rgb\"));\n\n for (let y = 0; y < self.height; y++) {\n for (let x = 0; x < self.width; x++) {\n const index = y * self.width * 3 + x * 3;\n self.stream[index + 0] = 0xff;\n self.stream[index + 1] = 0x80;\n self.stream[index + 2] = 0x10;\n }\n }\n\n const resource_path = go.get(\"#model\", \"texture0\");\n const args = { width: self.width, height: self.height, x: self.x, y: self.y, type: graphics.TEXTURE_TYPE_2D, format: graphics.TEXTURE_FORMAT_RGB, num_mip_maps: 1 };\n resource.set_texture(resource_path, args, self.buffer);\n },\n});\n\n// Update a texture from a buffer resource\ngo.property(\"my_buffer\", resource.buffer(\"/my_default_buffer.buffer\"));\n\nexport default defineScript({\n init(self) {\n const resource_path = go.get(\"#model\", \"texture0\");\n // the \"my_buffer\" resource is expected to hold 128 * 128 * 3 bytes!\n const args = {\n width: 128,\n height: 128,\n type: graphics.TEXTURE_TYPE_2D,\n format: graphics.TEXTURE_FORMAT_RGB,\n };\n // Note that the extra resource.get_buffer call is a requirement here\n // since the \"self.my_buffer\" is just pointing to a buffer resource path\n // and not an actual buffer object or buffer resource.\n resource.set_texture(resource_path, args, resource.get_buffer(self.my_buffer));\n },\n});\n\n// Update an existing 3D texture from a buffer\nexport default defineScript({\n init() {\n // create a buffer that can hold the data of a 8x8x8 texture\n const tbuffer = buffer.create(8 * 8 * 8, [{ name: hash(\"rgba\"), type: buffer.VALUE_TYPE_FLOAT32, count: 4 }]);\n const tstream = buffer.get_stream(tbuffer, hash(\"rgba\"));\n\n // populate the buffer with some data\n let index = 0;\n for (let z = 0; z < 8; z++) {\n for (let y = 0; y < 8; y++) {\n for (let x = 0; x < 8; x++) {\n tstream[index + 0] = x;\n tstream[index + 1] = y;\n tstream[index + 2] = z;\n tstream[index + 3] = 1.0;\n index = index + 4;\n }\n }\n }\n\n const t_args = {\n type: graphics.TEXTURE_TYPE_IMAGE_3D,\n width: 8,\n height: 8,\n depth: 8,\n format: resource.TEXTURE_FORMAT_RGBA32F,\n };\n\n // This expects that the texture resource \"/my_3d_texture.texturec\" already exists\n // and is a 3D texture resource. To create a dynamic 3D texture resource\n // use the \"resource.create_texture\" function.\n resource.set_texture(\"/my_3d_texture.texturec\", t_args, tbuffer);\n },\n});\n\n// Update texture 2nd array page with loaded texture from png\n// new_tex is resource handle of texture which was created via resource.create_resource\nconst tex_path = \"/bundle_resources/page_02.png\";\nconst [data] = sys.load_resource(tex_path);\nconst buf = image.load_buffer(data);\nresource.set_texture(\n new_tex,\n {\n type: graphics.TEXTURE_TYPE_2D_ARRAY,\n width: buf.width,\n height: buf.height,\n page: 1,\n format: graphics.TEXTURE_FORMAT_RGB,\n },\n buf.buffer,\n);\ngo.set(\"#mesh\", \"texture0\", new_tex);"
|
|
1286
|
+
}
|
|
1287
|
+
],
|
|
1288
|
+
"resource.texture": [
|
|
1289
|
+
{
|
|
1290
|
+
"sourceHash": "8cd63a7393c8a799",
|
|
1291
|
+
"ts": "// Load a texture and set it to a model:\ngo.property(\"my_texture\", resource.texture(\"/texture.png\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#model\", \"texture0\", self.my_texture);\n },\n});"
|
|
1292
|
+
}
|
|
1293
|
+
],
|
|
1294
|
+
"resource.tile_source": [
|
|
1295
|
+
{
|
|
1296
|
+
"sourceHash": "517b23c5ce0e56c6",
|
|
1297
|
+
"ts": "// Load tile source and set it to a tile map:\ngo.property(\"my_tile_source\", resource.tile_source(\"/tilesource.tilesource\"));\n\nexport default defineScript({\n init(self) {\n go.set(\"#tilemap\", \"tile_source\", self.my_tile_source);\n },\n});"
|
|
1298
|
+
}
|
|
1299
|
+
],
|
|
1300
|
+
"socket.gettime": [
|
|
1301
|
+
{
|
|
1302
|
+
"sourceHash": "184ed247033e9375",
|
|
1303
|
+
"ts": "// How to use the gettime() function to measure running time:\nconst t = socket.gettime();\n// do stuff\nprint(`${socket.gettime() - t} seconds elapsed`);"
|
|
1304
|
+
}
|
|
1305
|
+
],
|
|
1306
|
+
"socket.newtry": [
|
|
1307
|
+
{
|
|
1308
|
+
"sourceHash": "38a669dbf612b327",
|
|
1309
|
+
"ts": "// Perform operations on an open socket c:\n// create a try function that closes 'c' on error\nconst try_ = socket.newtry(() => c.close());\n// do everything reassured c will be closed\ntry_(c.send(\"hello there?\\r\\n\"));\nconst answer = try_(c.receive());\n// ...\ntry_(c.send(\"good bye\\r\\n\"));\nc.close();"
|
|
1310
|
+
}
|
|
1311
|
+
],
|
|
1312
|
+
"socket.protect": [
|
|
1313
|
+
{
|
|
1314
|
+
"sourceHash": "478d4974b491bda9",
|
|
1315
|
+
"ts": "const dostuff = socket.protect(() => {\n let try_ = socket.newtry();\n const c = try_(socket.connect(\"myserver.com\", 80));\n try_ = socket.newtry(() => c.close());\n try_(c.send(\"hello?\\r\\n\"));\n const answer = try_(c.receive());\n c.close();\n});\n\nconst [n, error] = dostuff();"
|
|
1316
|
+
}
|
|
1317
|
+
],
|
|
1318
|
+
"socket.skip": [
|
|
1319
|
+
{
|
|
1320
|
+
"sourceHash": "3a75c35a80c48e9e",
|
|
1321
|
+
"ts": "// Instead of doing the following with dummy variables:\n// get the status code and separator from SMTP server reply\nconst [dummy1, dummy2, code, sep] = string.find(line, \"^(%d%d%d)(.?)\");\n\n// You can skip a number of variables:\n// get the status code and separator from SMTP server reply\nconst [code, sep] = socket.skip(2, string.find(line, \"^(%d%d%d)(.?)\"));"
|
|
1322
|
+
}
|
|
1323
|
+
],
|
|
1324
|
+
"sound.get_group_gain": [
|
|
1325
|
+
{
|
|
1326
|
+
"sourceHash": "61179d97bacd989a",
|
|
1327
|
+
"ts": "// Get the mixer group gain for the \"soundfx\" and convert to dB:\nconst gain = sound.get_group_gain(\"soundfx\");\nconst gain_db = 60 * gain;"
|
|
1328
|
+
}
|
|
1329
|
+
],
|
|
1330
|
+
"sound.get_group_name": [
|
|
1331
|
+
{
|
|
1332
|
+
"sourceHash": "854009634c4288fe",
|
|
1333
|
+
"ts": "// Get the mixer group string names so we can show them as labels on a dev mixer overlay:\nconst groups = sound.get_groups();\nfor (const group of groups) {\n const name = sound.get_group_name(group);\n msg.post(\"/mixer_overlay#gui\", \"set_mixer_label\", { group: group, label: name });\n}"
|
|
1334
|
+
}
|
|
1335
|
+
],
|
|
1336
|
+
"sound.get_groups": [
|
|
1337
|
+
{
|
|
1338
|
+
"sourceHash": "70cee9ddf429f3b4",
|
|
1339
|
+
"ts": "// Get the mixer groups, set all gains to 0 except for \"master\" and \"soundfx\"\n// where gain is set to 1:\nconst groups = sound.get_groups();\nfor (const group of groups) {\n if (group === hash(\"master\") || group === hash(\"soundfx\")) {\n sound.set_group_gain(group, 1);\n } else {\n sound.set_group_gain(group, 0);\n }\n}"
|
|
1340
|
+
}
|
|
1341
|
+
],
|
|
1342
|
+
"sound.get_peak": [
|
|
1343
|
+
{
|
|
1344
|
+
"sourceHash": "d19e9bed622933bc",
|
|
1345
|
+
"ts": "// Get the peak gain from the \"master\" group and convert to dB for displaying:\nconst [left_p, right_p] = sound.get_peak(\"master\", 0.1);\nconst left_p_db = 20 * Math.log(left_p);\nconst right_p_db = 20 * Math.log(right_p);"
|
|
1346
|
+
}
|
|
1347
|
+
],
|
|
1348
|
+
"sound.get_rms": [
|
|
1349
|
+
{
|
|
1350
|
+
"sourceHash": "44e1ca26aadd606d",
|
|
1351
|
+
"ts": "// Get the RMS from the \"master\" group where a mono -1.94 dB sinewave is playing:\nconst [rms] = sound.get_rms(\"master\", 0.1); // throw away right channel.\nprint(rms); // => 0.56555819511414"
|
|
1352
|
+
}
|
|
1353
|
+
],
|
|
1354
|
+
"sound.is_music_playing": [
|
|
1355
|
+
{
|
|
1356
|
+
"sourceHash": "8ce948ed9fe23655",
|
|
1357
|
+
"ts": "// If music is playing, mute \"master\":\nif (sound.is_music_playing()) {\n // mute \"master\"\n sound.set_group_gain(\"master\", 0);\n}"
|
|
1358
|
+
}
|
|
1359
|
+
],
|
|
1360
|
+
"sound.is_phone_call_active": [
|
|
1361
|
+
{
|
|
1362
|
+
"sourceHash": "a1ec8c4ea71731c3",
|
|
1363
|
+
"ts": "// Test if a phone call is on-going:\nif (sound.is_phone_call_active()) {\n // do something sensible.\n}"
|
|
1364
|
+
}
|
|
1365
|
+
],
|
|
1366
|
+
"sound.pause": [
|
|
1367
|
+
{
|
|
1368
|
+
"sourceHash": "4cc9e8603f4c97e1",
|
|
1369
|
+
"ts": "// Assuming the script belongs to an instance with a sound-component with id\n// \"sound\", this will make the component pause all playing voices:\nsound.pause(\"#sound\", true);"
|
|
1370
|
+
}
|
|
1371
|
+
],
|
|
1372
|
+
"sound.play": [
|
|
1373
|
+
{
|
|
1374
|
+
"sourceHash": "fcfbfd341c41ec59",
|
|
1375
|
+
"ts": "// Assuming the script belongs to an instance with a sound-component with id\n// \"sound\", this will make the component play its sound after 1 second:\nsound.play(\"#sound\", { delay: 1, gain: 0.9, pan: -1.0 });\n\n// Using the callback argument, you can chain several sounds together:\nfunction sound_done(self, message_id, message, sender) {\n // play 'boom' sound fx when the countdown has completed\n if (message_id === hash(\"sound_done\") && message.play_id === self.countdown_id) {\n sound.play(\"#boom\", undefined, sound_done);\n }\n}\n\nexport default defineScript({\n init(self) {\n self.countdown_id = sound.play(\"#countdown\", undefined, sound_done);\n },\n});"
|
|
1376
|
+
}
|
|
1377
|
+
],
|
|
1378
|
+
"sound.set_gain": [
|
|
1379
|
+
{
|
|
1380
|
+
"sourceHash": "f798d01660f92d40",
|
|
1381
|
+
"ts": "// Assuming the script belongs to an instance with a sound-component with id\n// \"sound\", this will set the gain to 0.9\nsound.set_gain(\"#sound\", 0.9);"
|
|
1382
|
+
}
|
|
1383
|
+
],
|
|
1384
|
+
"sound.set_group_gain": [
|
|
1385
|
+
{
|
|
1386
|
+
"sourceHash": "c359845768e67ff0",
|
|
1387
|
+
"ts": "// Set mixer group gain on the \"soundfx\" group to 50% (-30dB):\nsound.set_group_gain(\"soundfx\", 0.5);"
|
|
1388
|
+
}
|
|
1389
|
+
],
|
|
1390
|
+
"sound.set_pan": [
|
|
1391
|
+
{
|
|
1392
|
+
"sourceHash": "a4ed2d3c8035f8c5",
|
|
1393
|
+
"ts": "// Assuming the script belongs to an instance with a sound-component with id\n// \"sound\", this will set the gain to 0.5\nsound.set_pan(\"#sound\", 0.5); // pan to the right"
|
|
1394
|
+
}
|
|
1395
|
+
],
|
|
1396
|
+
"sound.stop": [
|
|
1397
|
+
{
|
|
1398
|
+
"sourceHash": "a0a2dde807a266aa",
|
|
1399
|
+
"ts": "// Assuming the script belongs to an instance with a sound-component with id\n// \"sound\", this will make the component stop all playing voices:\nsound.stop(\"#sound\");\nconst id = sound.play(\"#sound\");\nsound.stop(\"#sound\", { play_id: id });"
|
|
1400
|
+
}
|
|
1401
|
+
],
|
|
1402
|
+
"sprite.play_flipbook": [
|
|
1403
|
+
{
|
|
1404
|
+
"sourceHash": "6bac8dc702dfffec",
|
|
1405
|
+
"ts": "// Assuming the sprite has id \"sprite\": play the \"jump\" animation followed by the\n// \"run\" animation:\nexport default defineScript({\n init() {\n const url = msg.url(\"#sprite\");\n sprite.play_flipbook(url, \"jump\", (self, message_id, message) => {\n if (message_id === hash(\"animation_done\") && message.id === hash(\"jump\")) {\n // jump animation done, chain with \"run\"\n sprite.play_flipbook(url, \"run\");\n }\n });\n },\n});"
|
|
1406
|
+
}
|
|
1407
|
+
],
|
|
1408
|
+
"sprite.reset_constant": [
|
|
1409
|
+
{
|
|
1410
|
+
"sourceHash": "6926e9e81858e982",
|
|
1411
|
+
"ts": "sprite.reset_constant(\"#sprite\", \"tint\");"
|
|
1412
|
+
}
|
|
1413
|
+
],
|
|
1414
|
+
"sprite.set_hflip": [
|
|
1415
|
+
{
|
|
1416
|
+
"sourceHash": "2d067cdccd1fb269",
|
|
1417
|
+
"ts": "// How to flip a sprite so it faces the horizontal movement (it is assumed that\n// the sprite component has id \"sprite\" and the original animation faces right):\nexport default defineScript({\n update(self, dt) {\n // calculate self.velocity somehow\n sprite.set_hflip(\"#sprite\", self.velocity.x < 0);\n },\n});"
|
|
1418
|
+
}
|
|
1419
|
+
],
|
|
1420
|
+
"sprite.set_vflip": [
|
|
1421
|
+
{
|
|
1422
|
+
"sourceHash": "89dcc94c14d785e2",
|
|
1423
|
+
"ts": "// How to flip a sprite in a game which negates gravity as a game mechanic (it is\n// assumed that the sprite component has id \"sprite\" and the original animation\n// is up-right):\nexport default defineScript({\n update(self, dt) {\n // calculate self.up_side_down somehow, then:\n sprite.set_vflip(\"#sprite\", self.up_side_down);\n },\n});"
|
|
1424
|
+
}
|
|
1425
|
+
],
|
|
1426
|
+
"sys.deserialize": [
|
|
1427
|
+
{
|
|
1428
|
+
"sourceHash": "3129688709daf585",
|
|
1429
|
+
"ts": "// Deserialize a table that was previously serialized:\nconst buffer = sys.serialize(my_table);\nconst table = sys.deserialize(buffer);"
|
|
1430
|
+
}
|
|
1431
|
+
],
|
|
1432
|
+
"sys.exists": [
|
|
1433
|
+
{
|
|
1434
|
+
"sourceHash": "7e98945102ff1ab7",
|
|
1435
|
+
"ts": "// Load data but return nil if path didn't exist\nif (!sys.exists(path)) {\n return undefined;\n}\nreturn sys.load(path); // returns {} if it failed"
|
|
1436
|
+
}
|
|
1437
|
+
],
|
|
1438
|
+
"sys.exit": [
|
|
1439
|
+
{
|
|
1440
|
+
"sourceHash": "c9d4d5d75509d158",
|
|
1441
|
+
"ts": "// This example demonstrates how to exit the application when some kind of quit\n// message is received (maybe from gui or similar):\nexport default defineScript({\n on_message(self, message_id, message, sender) {\n if (message_id === hash(\"quit\")) {\n sys.exit(0);\n }\n },\n});"
|
|
1442
|
+
}
|
|
1443
|
+
],
|
|
1444
|
+
"sys.get_application_info": [
|
|
1445
|
+
{
|
|
1446
|
+
"sourceHash": "e13c2cc712709832",
|
|
1447
|
+
"ts": "// Check if twitter is installed:\nconst sysinfo = sys.get_sys_info();\nlet twitter = {};\n\nif (sysinfo.system_name === \"Android\") {\n twitter = sys.get_application_info(\"com.twitter.android\");\n} else if (sysinfo.system_name === \"iPhone OS\") {\n twitter = sys.get_application_info(\"twitter:\");\n}\n\nif (twitter.installed) {\n // twitter is installed!\n}\n\n// Info.plist for the iOS app needs to list the schemes that are queried:\n// ...\n// <key>LSApplicationQueriesSchemes</key>\n// <array>\n// <string>twitter</string>\n// </array>\n// ..."
|
|
1448
|
+
}
|
|
1449
|
+
],
|
|
1450
|
+
"sys.get_application_path": [
|
|
1451
|
+
{
|
|
1452
|
+
"sourceHash": "69dd3a4397827973",
|
|
1453
|
+
"ts": "// Find a path where we can store data (the example path is on the macOS platform):\n// macOS: /Applications/my_game.app\nconst application_path = sys.get_application_path();\nprint(application_path); //> /Applications/my_game.app\n\n// Windows: C:\\Program Files\\my_game\\my_game.exe\nprint(application_path); //> C:\\Program Files\\my_game\n\n// Linux: /home/foobar/my_game/my_game\nprint(application_path); //> /home/foobar/my_game\n\n// Android package name: com.foobar.my_game\nprint(application_path); //> /data/user/0/com.foobar.my_game\n\n// iOS: my_game.app\nprint(application_path); //> /var/containers/Bundle/Applications/123456AB-78CD-90DE-12345678ABCD/my_game.app\n\n// HTML5: http://www.foobar.com/my_game/\nprint(application_path); //> http://www.foobar.com/my_game"
|
|
1454
|
+
}
|
|
1455
|
+
],
|
|
1456
|
+
"sys.get_config_boolean": [
|
|
1457
|
+
{
|
|
1458
|
+
"sourceHash": "dfccc454c2bdb792",
|
|
1459
|
+
"ts": "// Get user config value\nconst vsync = sys.get_config_boolean(\"display.vsync\", false);"
|
|
1460
|
+
}
|
|
1461
|
+
],
|
|
1462
|
+
"sys.get_config_int": [
|
|
1463
|
+
{
|
|
1464
|
+
"sourceHash": "f384eab53a7c1bda",
|
|
1465
|
+
"ts": "// Get user config value\nconst speed = sys.get_config_int(\"my_game.speed\", 20); // with default value\n\nconst testmode = sys.get_config_int(\"my_game.testmode\"); // without default value\nif (testmode !== undefined) {\n // do stuff\n}"
|
|
1466
|
+
}
|
|
1467
|
+
],
|
|
1468
|
+
"sys.get_config_number": [
|
|
1469
|
+
{
|
|
1470
|
+
"sourceHash": "2649f9c4111009bd",
|
|
1471
|
+
"ts": "// Get user config value\nconst speed = sys.get_config_number(\"my_game.speed\", 20.0);"
|
|
1472
|
+
}
|
|
1473
|
+
],
|
|
1474
|
+
"sys.get_config_string": [
|
|
1475
|
+
{
|
|
1476
|
+
"sourceHash": "4aeb12fca87c114c",
|
|
1477
|
+
"ts": "// Get user config value\nconst text = sys.get_config_string(\"my_game.text\", \"default text\");\n\n// Start the engine with a bootstrap config override and add a custom config value\n// $ dmengine --config=bootstrap.main_collection=/mytest.collectionc --config=mygame.testmode=1\n\n// Read the custom config value from the command line\nconst testmode = sys.get_config_int(\"mygame.testmode\");"
|
|
1478
|
+
}
|
|
1479
|
+
],
|
|
1480
|
+
"sys.get_connectivity": [
|
|
1481
|
+
{
|
|
1482
|
+
"sourceHash": "fbc6587958ab4c81",
|
|
1483
|
+
"ts": "// Check if we are connected through a cellular connection\nif (sys.NETWORK_CONNECTED_CELLULAR === sys.get_connectivity()) {\n print(\"Connected via cellular, avoid downloading big files!\");\n}"
|
|
1484
|
+
}
|
|
1485
|
+
],
|
|
1486
|
+
"sys.get_engine_info": [
|
|
1487
|
+
{
|
|
1488
|
+
"sourceHash": "d115807db2962da4",
|
|
1489
|
+
"ts": "// How to retrieve engine information:\n// Update version text label so our testers know what version we're running\nconst engine_info = sys.get_engine_info();\nconst version_str = `Defold ${engine_info.version}\\n${engine_info.version_sha1}`;\ngui.set_text(gui.get_node(\"version\"), version_str);"
|
|
1490
|
+
}
|
|
1491
|
+
],
|
|
1492
|
+
"sys.get_host_path": [
|
|
1493
|
+
{
|
|
1494
|
+
"sourceHash": "a059ecb3d55d5c22",
|
|
1495
|
+
"ts": "// Save data on the host\nconst host_path = sys.get_host_path(\"logs/test.txt\");\nsys.save(host_path, mytable);\n\n// Load data from the host\nconst host_path = sys.get_host_path(\"logs/test.txt\");\nconst table = sys.load(host_path);"
|
|
1496
|
+
}
|
|
1497
|
+
],
|
|
1498
|
+
"sys.get_ifaddrs": [
|
|
1499
|
+
{
|
|
1500
|
+
"sourceHash": "3a90b39ee24bf77b",
|
|
1501
|
+
"ts": "// How to get the IP address of interface \"en0\":\nconst ifaddrs = sys.get_ifaddrs();\nfor (const iface of ifaddrs) {\n if (iface.name === \"en0\") {\n const ip = iface.address;\n }\n}"
|
|
1502
|
+
}
|
|
1503
|
+
],
|
|
1504
|
+
"sys.get_save_file": [
|
|
1505
|
+
{
|
|
1506
|
+
"sourceHash": "d936178efa7a38ee",
|
|
1507
|
+
"ts": "// Find a path where we can store data:\nconst my_file_path = sys.get_save_file(\"my_game\", \"my_file\");\n// macOS: /Users/foobar/Library/Application Support/my_game/my_file\nprint(my_file_path); //> /Users/foobar/Library/Application Support/my_game/my_file\n\n// Windows: C:\\Users\\foobar\\AppData\\Roaming\\my_game\\my_file\nprint(my_file_path); //> C:\\Users\\foobar\\AppData\\Roaming\\my_game\\my_file\n\n// Linux: $XDG_DATA_HOME/my_game/my_file or /home/foobar/.my_game/my_file\n// Linux: Defaults to /home/foobar/.local/share/my_game/my_file if neither exist.\nprint(my_file_path); //> /home/foobar/.local/share/my_game/my_file\n\n// Android package name: com.foobar.packagename\nprint(my_file_path); //> /data/data/0/com.foobar.packagename/files/my_file\n\n// iOS: my_game.app\nprint(my_file_path); //> /var/mobile/Containers/Data/Application/123456AB-78CD-90DE-12345678ABCD/my_game/my_file\n\n// HTML5 path inside the IndexedDB: /data/.my_game/my_file or /.my_game/my_file\nprint(my_file_path); //> /data/.my_game/my_file"
|
|
1508
|
+
}
|
|
1509
|
+
],
|
|
1510
|
+
"sys.get_sys_info": [
|
|
1511
|
+
{
|
|
1512
|
+
"sourceHash": "637e648646538721",
|
|
1513
|
+
"ts": "// How to get system information:\nconst info = sys.get_sys_info();\nif (info.system_name === \"HTML5\") {\n // We are running in a browser.\n}"
|
|
1514
|
+
}
|
|
1515
|
+
],
|
|
1516
|
+
"sys.load": [
|
|
1517
|
+
{
|
|
1518
|
+
"sourceHash": "d3163ffbf2b24c09",
|
|
1519
|
+
"ts": "// Load data that was previously saved, e.g. an earlier game session:\nconst my_file_path = sys.get_save_file(\"my_game\", \"my_file\");\nconst my_table = sys.load(my_file_path);\nif (!next(my_table)) {\n // empty table\n}"
|
|
1520
|
+
}
|
|
1521
|
+
],
|
|
1522
|
+
"sys.load_buffer": [
|
|
1523
|
+
{
|
|
1524
|
+
"sourceHash": "106462121a6dfc78",
|
|
1525
|
+
"ts": "// Load binary data from a custom project resource:\nconst my_buffer = sys.load_buffer(\"/assets/my_level_data.bin\");\nconst data_str = buffer.get_bytes(my_buffer, \"data\");\nconst has_my_header = data_str.slice(0, 6) === \"D3F0LD\";\n\n// Load binary data from non-custom resource files on disk:\nconst asset_1 = sys.load_buffer(\"folder_next_to_binary/my_level_asset.txt\");\nconst asset_2 = sys.load_buffer(\"/my/absolute/path\");"
|
|
1526
|
+
}
|
|
1527
|
+
],
|
|
1528
|
+
"sys.load_buffer_async": [
|
|
1529
|
+
{
|
|
1530
|
+
"sourceHash": "6a383bca91cf11eb",
|
|
1531
|
+
"ts": "// Load binary data from a custom project resource and update a texture resource:\nfunction my_callback(self, request_id, result) {\n if (result.status === resource.REQUEST_STATUS_FINISHED) {\n resource.set_texture(\"/my_texture\", {}, result.buf); // texture args\n }\n}\n\nconst my_request = sys.load_buffer_async(\"/assets/my_level_data.bin\", my_callback);\n\n// Load binary data from non-custom resource files on disk:\nfunction my_callback(self, request_id, result) {\n if (result.status !== sys.REQUEST_STATUS_FINISHED) {\n // uh oh! File could not be found, do something graceful\n } else if (request_id === self.first_asset) {\n // result.buffer contains data from my_level_asset.bin\n } else if (request_id === self.second_asset) {\n // result.buffer contains data from 'my_level.bin'\n }\n}\n\nexport default defineScript({\n init(self) {\n self.first_asset = hash(\"folder_next_to_binary/my_level_asset.bin\");\n self.second_asset = hash(\"/some_absolute_path/my_level.bin\");\n self.first_request = sys.load_buffer_async(self.first_asset, my_callback);\n self.second_request = sys.load_buffer_async(self.second_asset, my_callback);\n },\n});"
|
|
1532
|
+
}
|
|
1533
|
+
],
|
|
1534
|
+
"sys.load_resource": [
|
|
1535
|
+
{
|
|
1536
|
+
"sourceHash": "6e77c0929b579d3c",
|
|
1537
|
+
"ts": "// Load level data into a string\nconst [data, error] = sys.load_resource(\"/assets/level_data.json\");\n// Decode json string to a table\nif (data) {\n const data_table = json.decode(data);\n pprint(data_table);\n} else {\n print(error);\n}"
|
|
1538
|
+
}
|
|
1539
|
+
],
|
|
1540
|
+
"sys.open_url": [
|
|
1541
|
+
{
|
|
1542
|
+
"sourceHash": "ca86f356d47ffba0",
|
|
1543
|
+
"ts": "// Open an URL:\nconst success = sys.open_url(\"http://www.defold.com\", { target: \"_blank\" });\nif (!success) {\n // could not open the url...\n}"
|
|
1544
|
+
}
|
|
1545
|
+
],
|
|
1546
|
+
"sys.reboot": [
|
|
1547
|
+
{
|
|
1548
|
+
"sourceHash": "37fa088e5c449462",
|
|
1549
|
+
"ts": "// How to reboot engine with a specific bootstrap collection.\nconst arg1 = \"--config=bootstrap.main_collection=/my.collectionc\";\nconst arg2 = \"build/game.projectc\";\nsys.reboot(arg1, arg2);"
|
|
1550
|
+
}
|
|
1551
|
+
],
|
|
1552
|
+
"sys.save": [
|
|
1553
|
+
{
|
|
1554
|
+
"sourceHash": "20939b04814e98af",
|
|
1555
|
+
"ts": "// Save data:\nconst my_table = [];\nmy_table.push(\"my_value\");\nconst my_file_path = sys.get_save_file(\"my_game\", \"my_file\");\nsys.save(my_file_path, my_table);"
|
|
1556
|
+
}
|
|
1557
|
+
],
|
|
1558
|
+
"sys.serialize": [
|
|
1559
|
+
{
|
|
1560
|
+
"sourceHash": "74b6fd38d9f6ea16",
|
|
1561
|
+
"ts": "// Serialize table:\nconst my_table = [];\nmy_table.push(\"my_value\");\nconst buffer = sys.serialize(my_table);"
|
|
1562
|
+
}
|
|
1563
|
+
],
|
|
1564
|
+
"sys.set_connectivity_host": [
|
|
1565
|
+
{
|
|
1566
|
+
"sourceHash": "b520f6352a5c8db1",
|
|
1567
|
+
"ts": "sys.set_connectivity_host(\"www.google.com\");"
|
|
1568
|
+
}
|
|
1569
|
+
],
|
|
1570
|
+
"sys.set_engine_throttle": [
|
|
1571
|
+
{
|
|
1572
|
+
"sourceHash": "66eae5cfa23de217",
|
|
1573
|
+
"ts": "// Disable throttling\nsys.set_engine_throttle(false);\n\n// Enable throttling\nsys.set_engine_throttle(true, 1.5);"
|
|
1574
|
+
}
|
|
1575
|
+
],
|
|
1576
|
+
"sys.set_error_handler": [
|
|
1577
|
+
{
|
|
1578
|
+
"sourceHash": "7346508f30f50bc9",
|
|
1579
|
+
"ts": "// Install error handler that just prints the errors\nfunction my_error_handler(source, message, traceback) {\n print(source); //> lua\n print(message); //> main/my.script:10: attempt to perform arithmetic on a string value\n print(traceback); //> stack traceback:\n //> main/test.script:10: in function 'boom'\n //> main/test.script:15: in function <main/my.script:13>\n}\n\nfunction boom() {\n return 10 + \"string\";\n}\n\nexport default defineScript({\n init() {\n sys.set_error_handler(my_error_handler);\n boom();\n },\n});"
|
|
1580
|
+
}
|
|
1581
|
+
],
|
|
1582
|
+
"sys.set_render_enable": [
|
|
1583
|
+
{
|
|
1584
|
+
"sourceHash": "aa4a8e62d5eddb0b",
|
|
1585
|
+
"ts": "// Disable rendering\nsys.set_render_enable(false);"
|
|
1586
|
+
}
|
|
1587
|
+
],
|
|
1588
|
+
"sys.set_update_frequency": [
|
|
1589
|
+
{
|
|
1590
|
+
"sourceHash": "5bb1f7705e3f0bb8",
|
|
1591
|
+
"ts": "// Setting the update frequency to 60 frames per second\nsys.set_update_frequency(60);"
|
|
1592
|
+
}
|
|
1593
|
+
],
|
|
1594
|
+
"sys.set_vsync_swap_interval": [
|
|
1595
|
+
{
|
|
1596
|
+
"sourceHash": "95117be25e11bf9f",
|
|
1597
|
+
"ts": "// Setting the swap intervall to swap every v-blank\nsys.set_vsync_swap_interval(1);"
|
|
1598
|
+
}
|
|
1599
|
+
],
|
|
1600
|
+
"tilemap.get_bounds": [
|
|
1601
|
+
{
|
|
1602
|
+
"sourceHash": "67dabf47ed103b24",
|
|
1603
|
+
"ts": "// get the level bounds.\nconst [x, y, w, h] = tilemap.get_bounds(\"/level#tilemap\");"
|
|
1604
|
+
}
|
|
1605
|
+
],
|
|
1606
|
+
"tilemap.get_tile": [
|
|
1607
|
+
{
|
|
1608
|
+
"sourceHash": "a4284f541bd0cf03",
|
|
1609
|
+
"ts": "// get the tile under the player.\nconst tileno = tilemap.get_tile(\"/level#tilemap\", \"foreground\", self.player_x, self.player_y);"
|
|
1610
|
+
}
|
|
1611
|
+
],
|
|
1612
|
+
"tilemap.get_tile_info": [
|
|
1613
|
+
{
|
|
1614
|
+
"sourceHash": "a05cf9c118a0d36c",
|
|
1615
|
+
"ts": "// get the tile under the player.\nconst tile_info = tilemap.get_tile_info(\"/level#tilemap\", \"foreground\", self.player_x, self.player_y);\npprint(tile_info);\n// {\n// index = 0,\n// h_flip = false,\n// v_flip = true,\n// rotate_90 = false\n// }"
|
|
1616
|
+
}
|
|
1617
|
+
],
|
|
1618
|
+
"tilemap.get_tiles": [
|
|
1619
|
+
{
|
|
1620
|
+
"sourceHash": "61b14de4991f966b",
|
|
1621
|
+
"ts": "const [left, bottom, columns_count, rows_count] = tilemap.get_bounds(\"#tilemap\");\nconst tiles = tilemap.get_tiles(\"#tilemap\", \"layer\");\nlet tile = 0;\nlet count = 0;\nfor (let row_index = bottom; row_index <= bottom + rows_count - 1; row_index++) {\n for (let column_index = left; column_index <= left + columns_count - 1; column_index++) {\n tile = tiles[row_index][column_index];\n count = count + 1;\n }\n}"
|
|
1622
|
+
}
|
|
1623
|
+
],
|
|
1624
|
+
"tilemap.reset_constant": [
|
|
1625
|
+
{
|
|
1626
|
+
"sourceHash": "c58f2e21e615eaba",
|
|
1627
|
+
"ts": "tilemap.reset_constant(\"#tilemap\", \"tint\");"
|
|
1628
|
+
}
|
|
1629
|
+
],
|
|
1630
|
+
"tilemap.set_tile": [
|
|
1631
|
+
{
|
|
1632
|
+
"sourceHash": "bc75d2a572ada34d",
|
|
1633
|
+
"ts": "// Clear the tile under the player.\ntilemap.set_tile(\"/level#tilemap\", \"foreground\", self.player_x, self.player_y, 0);\n\n// Set tile with different combination of flip and rotation\ntilemap.set_tile(\"#tilemap\", \"layer1\", x, y, 0, tilemap.H_FLIP + tilemap.V_FLIP + tilemap.ROTATE_90);\ntilemap.set_tile(\"#tilemap\", \"layer1\", x, y, 0, tilemap.H_FLIP + tilemap.ROTATE_270);\ntilemap.set_tile(\"#tilemap\", \"layer1\", x, y, 0, tilemap.V_FLIP + tilemap.H_FLIP);\ntilemap.set_tile(\"#tilemap\", \"layer1\", x, y, 0, tilemap.ROTATE_180);"
|
|
1634
|
+
}
|
|
1635
|
+
],
|
|
1636
|
+
"tilemap.set_visible": [
|
|
1637
|
+
{
|
|
1638
|
+
"sourceHash": "9089660809ece706",
|
|
1639
|
+
"ts": "// Disable rendering of the layer\ntilemap.set_visible(\"/level#tilemap\", \"foreground\", false);"
|
|
1640
|
+
}
|
|
1641
|
+
],
|
|
1642
|
+
"timer.cancel": [
|
|
1643
|
+
{
|
|
1644
|
+
"sourceHash": "00f46bbbb35028b3",
|
|
1645
|
+
"ts": "self.handle = timer.delay(1, true, () => print(\"print every second\"));\n// ...\nconst result = timer.cancel(self.handle);\nif (!result) {\n print(\"the timer is already cancelled\");\n}"
|
|
1646
|
+
}
|
|
1647
|
+
],
|
|
1648
|
+
"timer.delay": [
|
|
1649
|
+
{
|
|
1650
|
+
"sourceHash": "d50acfc0a9d925a8",
|
|
1651
|
+
"ts": "// A simple one-shot timer\ntimer.delay(1, false, () => print(\"print in one second\"));\n\n// Repetitive timer which canceled after 10 calls\nfunction call_every_second(self, handle, time_elapsed) {\n self.counter = self.counter + 1;\n print(\"Call #\", self.counter);\n if (self.counter === 10) {\n timer.cancel(handle); // cancel timer after 10 calls\n }\n}\n\nself.counter = 0;\ntimer.delay(1, true, call_every_second);"
|
|
1652
|
+
}
|
|
1653
|
+
],
|
|
1654
|
+
"timer.get_info": [
|
|
1655
|
+
{
|
|
1656
|
+
"sourceHash": "f2fcacbd1849146e",
|
|
1657
|
+
"ts": "self.handle = timer.delay(1, true, () => print(\"print every second\"));\n// ...\nconst result = timer.get_info(self.handle);\nif (!result) {\n print(\"the timer is already cancelled or complete\");\n} else {\n pprint(result); // delay, time_remaining, repeating\n}"
|
|
1658
|
+
}
|
|
1659
|
+
],
|
|
1660
|
+
"timer.trigger": [
|
|
1661
|
+
{
|
|
1662
|
+
"sourceHash": "3d4814c0a3380acf",
|
|
1663
|
+
"ts": "self.handle = timer.delay(1, true, () => print(\"print every second or manually by timer.trigger\"));\n// ...\nconst result = timer.trigger(self.handle);\nif (!result) {\n print(\"the timer is already cancelled or complete\");\n}"
|
|
1664
|
+
}
|
|
1665
|
+
],
|
|
1666
|
+
"update": [
|
|
1667
|
+
{
|
|
1668
|
+
"sourceHash": "1019c7620d797753",
|
|
1669
|
+
"ts": "// This example demonstrates how to move a game object instance through the script component:\nexport default defineScript({\n init() {\n // set initial velocity to be 1 along world x-axis\n return { my_velocity: vmath.vector3(1, 0, 0) };\n },\n\n update(self, dt) {\n // move the game object instance\n go.set_position(go.get_position().add(self.my_velocity.mul(dt)));\n },\n});"
|
|
1670
|
+
},
|
|
1671
|
+
{
|
|
1672
|
+
"sourceHash": "f4f87939dbdd5fc3",
|
|
1673
|
+
"ts": "// This example demonstrates how to update a text node that displays game score\n// in a counting fashion. It is assumed that the gui component receives messages\n// from the game when a new score is to be shown.\nexport default defineGuiScript({\n init(self) {\n // fetch the score text node for later use (assumes it is called \"score\")\n self.score_node = gui.get_node(\"score\");\n // keep track of the current score counted up so far\n self.current_score = 0;\n // keep track of the target score we should count up to\n self.target_score = 0;\n // how fast we will update the score, in score/second\n self.score_update_speed = 1;\n },\n\n update(self, dt) {\n // check if target score is more than current score\n if (self.current_score < self.target_score) {\n // increment current score according to the speed\n self.current_score = self.current_score + dt * self.score_update_speed;\n // check if we went past the target score, clamp current score in that case\n if (self.current_score > self.target_score) {\n self.current_score = self.target_score;\n }\n // update the score text node\n gui.set_text(self.score_node, \"\" + math.floor(self.current_score));\n }\n },\n\n on_message(self, message_id, message) {\n // check the message\n if (message_id === hash(\"set_score\")) {\n self.target_score = message.score;\n }\n },\n});"
|
|
1674
|
+
}
|
|
1675
|
+
],
|
|
1676
|
+
"vmath.clamp": [
|
|
1677
|
+
{
|
|
1678
|
+
"sourceHash": "ce47102e76e3186d",
|
|
1679
|
+
"ts": "const value1 = 56;\nprint(vmath.clamp(value1, 89, 134)); // => 89\nconst v2 = vmath.vector3(190, 190, -10);\nprint(vmath.clamp(v2, -50, 150)); // => vmath.vector3(150, 150, -10)\nconst v3 = vmath.vector4(30, -30, 45, 1);\nprint(vmath.clamp(v3, 0, 20)); // => vmath.vector4(20, 0, 20, 1)\n\nconst min_v = vmath.vector4(0, -10, -10, 1);\nprint(vmath.clamp(v3, min_v, 20)); // => vmath.vector4(20, -10, 20, 1)"
|
|
1680
|
+
}
|
|
1681
|
+
],
|
|
1682
|
+
"vmath.conj": [
|
|
1683
|
+
{
|
|
1684
|
+
"sourceHash": "d9d7d7193243f1a7",
|
|
1685
|
+
"ts": "const quat = vmath.quat(1, 2, 3, 4);\nprint(vmath.conj(quat)); // => vmath.quat(-1, -2, -3, 4)"
|
|
1686
|
+
}
|
|
1687
|
+
],
|
|
1688
|
+
"vmath.cross": [
|
|
1689
|
+
{
|
|
1690
|
+
"sourceHash": "49cf4657cc17973f",
|
|
1691
|
+
"ts": "const vec1 = vmath.vector3(1, 0, 0);\nconst vec2 = vmath.vector3(0, 1, 0);\nprint(vmath.cross(vec1, vec2)); // => vmath.vector3(0, 0, 1)\nconst vec3 = vmath.vector3(-1, 0, 0);\nprint(vmath.cross(vec1, vec3)); // => vmath.vector3(0, -0, 0)"
|
|
1692
|
+
}
|
|
1693
|
+
],
|
|
1694
|
+
"vmath.dot": [
|
|
1695
|
+
{
|
|
1696
|
+
"sourceHash": "4f4a1c2d340af81b",
|
|
1697
|
+
"ts": "if (vmath.dot(vector1, vector2) === 0) {\n // The two vectors are perpendicular (at right-angles to each other)\n // ...\n}"
|
|
1698
|
+
}
|
|
1699
|
+
],
|
|
1700
|
+
"vmath.euler_to_quat": [
|
|
1701
|
+
{
|
|
1702
|
+
"sourceHash": "e856805279355e1d",
|
|
1703
|
+
"ts": "const q = vmath.euler_to_quat(0, 45, 90);\nprint(q); // => vmath.quat(0.27059805393219, 0.27059805393219, 0.65328145027161, 0.65328145027161)\n\nconst v = vmath.vector3(0, 0, 90);\nprint(vmath.euler_to_quat(v)); // => vmath.quat(0, 0, 0.70710676908493, 0.70710676908493)"
|
|
1704
|
+
}
|
|
1705
|
+
],
|
|
1706
|
+
"vmath.inv": [
|
|
1707
|
+
{
|
|
1708
|
+
"sourceHash": "abd36cc3e2b23aaf",
|
|
1709
|
+
"ts": "const mat1 = vmath.matrix4_rotation_z(3.141592653);\nconst mat2 = vmath.inv(mat1);\n// M * inv(M) = identity matrix\nprint(mat1.mul(mat2)); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)"
|
|
1710
|
+
}
|
|
1711
|
+
],
|
|
1712
|
+
"vmath.length": [
|
|
1713
|
+
{
|
|
1714
|
+
"sourceHash": "740d91676dd23d10",
|
|
1715
|
+
"ts": "if (vmath.length(self.velocity) < max_velocity) {\n // The speed (velocity vector) is below max.\n\n // TODO: max_velocity can be expressed as squared\n // so we can compare with length_sqr() instead.\n // ...\n}"
|
|
1716
|
+
}
|
|
1717
|
+
],
|
|
1718
|
+
"vmath.length_sqr": [
|
|
1719
|
+
{
|
|
1720
|
+
"sourceHash": "221e411fbcc2c4f8",
|
|
1721
|
+
"ts": "if (vmath.length_sqr(vector1) < vmath.length_sqr(vector2)) {\n // Vector 1 has less magnitude than vector 2\n // ...\n}"
|
|
1722
|
+
}
|
|
1723
|
+
],
|
|
1724
|
+
"vmath.lerp": [
|
|
1725
|
+
{
|
|
1726
|
+
"sourceHash": "8e7a50a5fc602639",
|
|
1727
|
+
"ts": "export default defineScript({\n init() {\n return { t: 0 };\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startpos = vmath.vector3(0, 600, 0);\n const endpos = vmath.vector3(600, 0, 0);\n const pos = vmath.lerp(self.t, startpos, endpos);\n go.set_position(pos, \"go\");\n }\n },\n});"
|
|
1728
|
+
},
|
|
1729
|
+
{
|
|
1730
|
+
"sourceHash": "7cf8c0c1679ab05b",
|
|
1731
|
+
"ts": "export default defineScript({\n init(self) {\n self.t = 0;\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startrot = vmath.quat_rotation_z(0);\n const endrot = vmath.quat_rotation_z(3.141592653);\n const rot = vmath.lerp(self.t, startrot, endrot);\n go.set_rotation(rot, \"go\");\n }\n },\n});"
|
|
1732
|
+
},
|
|
1733
|
+
{
|
|
1734
|
+
"sourceHash": "0f4fdfe7a9a39df7",
|
|
1735
|
+
"ts": "export default defineScript({\n init(self) {\n self.t = 0;\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startx = 0;\n const endx = 600;\n const x = vmath.lerp(self.t, startx, endx);\n go.set_position(vmath.vector3(x, 100, 0), \"go\");\n }\n },\n});"
|
|
1736
|
+
}
|
|
1737
|
+
],
|
|
1738
|
+
"vmath.matrix4": [
|
|
1739
|
+
{
|
|
1740
|
+
"sourceHash": "bb0da32d40dfd5fa",
|
|
1741
|
+
"ts": "const mat = vmath.matrix4();\nprint(mat); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)\n// get column 0:\nprint(mat.c0); // => vmath.vector4(1, 0, 0, 0)\n// get the value in row 3 and column 2:\nprint(mat.m32); // => 0"
|
|
1742
|
+
},
|
|
1743
|
+
{
|
|
1744
|
+
"sourceHash": "cb17c3e4b6cdc68e",
|
|
1745
|
+
"ts": "const mat1 = vmath.matrix4_rotation_x(3.141592653);\nconst mat2 = vmath.matrix4(mat1);\nif (mat1 === mat2) {\n // yes, they are equal\n print(mat2); // => vmath.matrix4(1, 0, 0, 0, 0, -1, 8.7422776573476e-08, 0, 0, -8.7422776573476e-08, -1, 0, 0, 0, 0, 1)\n}"
|
|
1746
|
+
}
|
|
1747
|
+
],
|
|
1748
|
+
"vmath.matrix4_axis_angle": [
|
|
1749
|
+
{
|
|
1750
|
+
"sourceHash": "92382085d95e2a17",
|
|
1751
|
+
"ts": "const vec = vmath.vector4(1, 1, 0, 0);\nconst axis = vmath.vector3(0, 0, 1); // z-axis\nconst mat = vmath.matrix4_axis_angle(axis, 3.141592653);\nprint(mat.mul(vec)); // => vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)"
|
|
1752
|
+
}
|
|
1753
|
+
],
|
|
1754
|
+
"vmath.matrix4_compose": [
|
|
1755
|
+
{
|
|
1756
|
+
"sourceHash": "13fb0a04d5414e2e",
|
|
1757
|
+
"ts": "const translation = vmath.vector3(103, -95, 14);\nconst quat = vmath.quat(1, 2, 3, 4);\nconst scale = vmath.vector3(1, 0.5, 0.5);\nconst result = vmath.matrix4_compose(translation, quat, scale);\nprint(result); // => vmath.matrix4(-25, -10, 11, 103, 28, -9.5, 2, -95, -10, 10, -4.5, 14, 0, 0, 0, 1)"
|
|
1758
|
+
}
|
|
1759
|
+
],
|
|
1760
|
+
"vmath.matrix4_frustum": [
|
|
1761
|
+
{
|
|
1762
|
+
"sourceHash": "f7ad37e0c5cb348a",
|
|
1763
|
+
"ts": "// Construct a projection frustum with a vertical and horizontal FOV of\n// 45 degrees. Useful for rendering a square view.\nconst proj = vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000);\nrender.set_projection(proj);"
|
|
1764
|
+
}
|
|
1765
|
+
],
|
|
1766
|
+
"vmath.matrix4_look_at": [
|
|
1767
|
+
{
|
|
1768
|
+
"sourceHash": "90bdec3f296cdb34",
|
|
1769
|
+
"ts": "// Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV, aspect ratio 4:3.\nconst eye = vmath.vector3(0, 0, 100);\nconst look_at = vmath.vector3(0, 0, 0);\nconst up = vmath.vector3(0, 1, 0);\nconst view = vmath.matrix4_look_at(eye, look_at, up);\nrender.set_view(view);\nconst proj = vmath.matrix4_perspective(3.141592 / 2, 4 / 3, 1, 1000);\nrender.set_projection(proj);"
|
|
1770
|
+
}
|
|
1771
|
+
],
|
|
1772
|
+
"vmath.matrix4_orthographic": [
|
|
1773
|
+
{
|
|
1774
|
+
"sourceHash": "5e4ccc690aa0a732",
|
|
1775
|
+
"ts": "// Set up an orthographic projection based on the width and height of the\n// game window.\nconst w = render.get_width();\nconst h = render.get_height();\nconst proj = vmath.matrix4_orthographic(-w / 2, w / 2, -h / 2, h / 2, -1000, 1000);\nrender.set_projection(proj);"
|
|
1776
|
+
}
|
|
1777
|
+
],
|
|
1778
|
+
"vmath.matrix4_perspective": [
|
|
1779
|
+
{
|
|
1780
|
+
"sourceHash": "90bdec3f296cdb34",
|
|
1781
|
+
"ts": "// Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV, aspect ratio 4:3.\nconst eye = vmath.vector3(0, 0, 100);\nconst look_at = vmath.vector3(0, 0, 0);\nconst up = vmath.vector3(0, 1, 0);\nconst view = vmath.matrix4_look_at(eye, look_at, up);\nrender.set_view(view);\nconst proj = vmath.matrix4_perspective(3.141592 / 2, 4 / 3, 1, 1000);\nrender.set_projection(proj);"
|
|
1782
|
+
}
|
|
1783
|
+
],
|
|
1784
|
+
"vmath.matrix4_quat": [
|
|
1785
|
+
{
|
|
1786
|
+
"sourceHash": "c9a567a902c8a77d",
|
|
1787
|
+
"ts": "const vec = vmath.vector4(1, 1, 0, 0);\nconst quat = vmath.quat_rotation_z(3.141592653);\nconst mat = vmath.matrix4_quat(quat);\nprint(mat.mul(vec)); // => vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000)"
|
|
1788
|
+
}
|
|
1789
|
+
],
|
|
1790
|
+
"vmath.matrix4_rotation_x": [
|
|
1791
|
+
{
|
|
1792
|
+
"sourceHash": "36050c10eab8eadb",
|
|
1793
|
+
"ts": "const vec = vmath.vector4(1, 1, 0, 0);\nconst mat = vmath.matrix4_rotation_x(3.141592653);\nprint(mat.mul(vec)); // => vmath.vector4(1, -1, -8.7422776573476e-08, 0)"
|
|
1794
|
+
}
|
|
1795
|
+
],
|
|
1796
|
+
"vmath.matrix4_rotation_y": [
|
|
1797
|
+
{
|
|
1798
|
+
"sourceHash": "044fdf9b69dcb597",
|
|
1799
|
+
"ts": "const vec = vmath.vector4(1, 1, 0, 0);\nconst mat = vmath.matrix4_rotation_y(3.141592653);\nprint(mat.mul(vec)); // => vmath.vector4(-1, 1, 8.7422776573476e-08, 0)"
|
|
1800
|
+
}
|
|
1801
|
+
],
|
|
1802
|
+
"vmath.matrix4_rotation_z": [
|
|
1803
|
+
{
|
|
1804
|
+
"sourceHash": "2c2de878e481f0e9",
|
|
1805
|
+
"ts": "const vec = vmath.vector4(1, 1, 0, 0);\nconst mat = vmath.matrix4_rotation_z(3.141592653);\nprint(mat.mul(vec)); // => vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)"
|
|
1806
|
+
}
|
|
1807
|
+
],
|
|
1808
|
+
"vmath.matrix4_scale": [
|
|
1809
|
+
{
|
|
1810
|
+
"sourceHash": "e1ef381cf831b464",
|
|
1811
|
+
"ts": "const scale = vmath.vector3(1, 0.5, 0.5);\nconst result = vmath.matrix4_scale(scale);\nprint(result); // => vmath.matrix4(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)"
|
|
1812
|
+
},
|
|
1813
|
+
{
|
|
1814
|
+
"sourceHash": "84ceaef2fedf510b",
|
|
1815
|
+
"ts": "const result = vmath.matrix4_scale(0.5);\nprint(result); // => vmath.matrix4(0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)"
|
|
1816
|
+
},
|
|
1817
|
+
{
|
|
1818
|
+
"sourceHash": "1e5af1821561f929",
|
|
1819
|
+
"ts": "const result = vmath.matrix4_scale(1, 0.5, 0.5);\nprint(result); // => vmath.matrix4(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)"
|
|
1820
|
+
}
|
|
1821
|
+
],
|
|
1822
|
+
"vmath.matrix4_translation": [
|
|
1823
|
+
{
|
|
1824
|
+
"sourceHash": "3b57dbafcbacb5e1",
|
|
1825
|
+
"ts": "// Set camera view from custom view and translation matrices.\nconst mat_trans = vmath.matrix4_translation(vmath.vector3(0, 10, 100));\nconst mat_view = vmath.matrix4_rotation_y(-3.141592 / 4);\nrender.set_view(mat_view.mul(mat_trans));"
|
|
1826
|
+
}
|
|
1827
|
+
],
|
|
1828
|
+
"vmath.mul_per_elem": [
|
|
1829
|
+
{
|
|
1830
|
+
"sourceHash": "49995280c8b8dc5a",
|
|
1831
|
+
"ts": "const blend_color = vmath.mul_per_elem(color1, color2);"
|
|
1832
|
+
}
|
|
1833
|
+
],
|
|
1834
|
+
"vmath.normalize": [
|
|
1835
|
+
{
|
|
1836
|
+
"sourceHash": "86752f1a5eb02e85",
|
|
1837
|
+
"ts": "const vec = vmath.vector3(1, 2, 3);\nconst norm_vec = vmath.normalize(vec);\nprint(norm_vec); // => vmath.vector3(0.26726123690605, 0.5345224738121, 0.80178368091583)\nprint(vmath.length(norm_vec)); // => 0.99999994039536"
|
|
1838
|
+
}
|
|
1839
|
+
],
|
|
1840
|
+
"vmath.ortho_inv": [
|
|
1841
|
+
{
|
|
1842
|
+
"sourceHash": "4fc2428e2d7152d4",
|
|
1843
|
+
"ts": "const mat1 = vmath.matrix4_rotation_z(3.141592653);\nconst mat2 = vmath.ortho_inv(mat1);\n// M * inv(M) = identity matrix\nprint(mat1.mul(mat2)); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)"
|
|
1844
|
+
}
|
|
1845
|
+
],
|
|
1846
|
+
"vmath.project": [
|
|
1847
|
+
{
|
|
1848
|
+
"sourceHash": "01772c731fb899ae",
|
|
1849
|
+
"ts": "const v1 = vmath.vector3(1, 1, 0);\nconst v2 = vmath.vector3(2, 0, 0);\nprint(vmath.project(v1, v2)); // => 0.5"
|
|
1850
|
+
}
|
|
1851
|
+
],
|
|
1852
|
+
"vmath.quat": [
|
|
1853
|
+
{
|
|
1854
|
+
"sourceHash": "0c75719779526345",
|
|
1855
|
+
"ts": "const quat = vmath.quat(1, 2, 3, 4);\nprint(quat); // => vmath.quat(1, 2, 3, 4)"
|
|
1856
|
+
},
|
|
1857
|
+
{
|
|
1858
|
+
"sourceHash": "15093ea7870639b5",
|
|
1859
|
+
"ts": "const quat = vmath.quat();\nprint(quat); // => vmath.quat(0, 0, 0, 1)\nprint(quat.w); // => 1"
|
|
1860
|
+
},
|
|
1861
|
+
{
|
|
1862
|
+
"sourceHash": "0c6183dc8c7af746",
|
|
1863
|
+
"ts": "const quat1 = vmath.quat(1, 2, 3, 4);\nconst quat2 = vmath.quat(quat1);\nif (quat1 === quat2) {\n // yes, they are equal\n print(quat2); // => vmath.quat(1, 2, 3, 4)\n}"
|
|
1864
|
+
}
|
|
1865
|
+
],
|
|
1866
|
+
"vmath.quat_axis_angle": [
|
|
1867
|
+
{
|
|
1868
|
+
"sourceHash": "40a0376b8995b7e9",
|
|
1869
|
+
"ts": "const axis = vmath.vector3(1, 0, 0);\nconst rot = vmath.quat_axis_angle(axis, 3.141592653);\nconst vec = vmath.vector3(1, 1, 0);\nprint(vmath.rotate(rot, vec)); // => vmath.vector3(1, -1, -8.7422776573476e-08)"
|
|
1870
|
+
}
|
|
1871
|
+
],
|
|
1872
|
+
"vmath.quat_basis": [
|
|
1873
|
+
{
|
|
1874
|
+
"sourceHash": "fd27ab961cbc4d89",
|
|
1875
|
+
"ts": "// Axis rotated 90 degrees around z.\nconst rot_x = vmath.vector3(0, -1, 0);\nconst rot_y = vmath.vector3(1, 0, 0);\nconst z = vmath.vector3(0, 0, 1);\nconst rot1 = vmath.quat_basis(rot_x, rot_y, z);\nconst rot2 = vmath.quat_from_to(vmath.vector3(0, 1, 0), vmath.vector3(1, 0, 0));\nif (rot1 === rot2) {\n // These quaternions are equal!\n print(rot2); // => vmath.quat(0, 0, -0.70710676908493, 0.70710676908493)\n}"
|
|
1876
|
+
}
|
|
1877
|
+
],
|
|
1878
|
+
"vmath.quat_from_to": [
|
|
1879
|
+
{
|
|
1880
|
+
"sourceHash": "68f8b7315dcf840f",
|
|
1881
|
+
"ts": "const v1 = vmath.vector3(1, 0, 0);\nconst v2 = vmath.vector3(0, 1, 0);\nconst rot = vmath.quat_from_to(v1, v2);\nprint(vmath.rotate(rot, v1)); // => vmath.vector3(0, 0.99999994039536, 0)"
|
|
1882
|
+
}
|
|
1883
|
+
],
|
|
1884
|
+
"vmath.quat_rotation_x": [
|
|
1885
|
+
{
|
|
1886
|
+
"sourceHash": "6fe4e9000a17ebe1",
|
|
1887
|
+
"ts": "const rot = vmath.quat_rotation_x(3.141592653);\nconst vec = vmath.vector3(1, 1, 0);\nprint(vmath.rotate(rot, vec)); // => vmath.vector3(1, -1, -8.7422776573476e-08)"
|
|
1888
|
+
}
|
|
1889
|
+
],
|
|
1890
|
+
"vmath.quat_rotation_y": [
|
|
1891
|
+
{
|
|
1892
|
+
"sourceHash": "e831483753250149",
|
|
1893
|
+
"ts": "const rot = vmath.quat_rotation_y(3.141592653);\nconst vec = vmath.vector3(1, 1, 0);\nprint(vmath.rotate(rot, vec)); // => vmath.vector3(-1, 1, 8.7422776573476e-08)"
|
|
1894
|
+
}
|
|
1895
|
+
],
|
|
1896
|
+
"vmath.quat_rotation_z": [
|
|
1897
|
+
{
|
|
1898
|
+
"sourceHash": "012e00b47b87f991",
|
|
1899
|
+
"ts": "const rot = vmath.quat_rotation_z(3.141592653);\nconst vec = vmath.vector3(1, 1, 0);\nprint(vmath.rotate(rot, vec)); // => vmath.vector3(-0.99999988079071, -1, 0)"
|
|
1900
|
+
}
|
|
1901
|
+
],
|
|
1902
|
+
"vmath.quat_to_euler": [
|
|
1903
|
+
{
|
|
1904
|
+
"sourceHash": "99474004e95ed10c",
|
|
1905
|
+
"ts": "const q = vmath.quat_rotation_z(math.rad(90));\nprint(vmath.quat_to_euler(q)); // => 0 0 90\n\nconst q2 = vmath.quat_rotation_y(math.rad(45)).mul(vmath.quat_rotation_z(math.rad(90)));\nconst [ex, ey, ez] = vmath.quat_to_euler(q2);\nconst v = vmath.vector3(ex, ey, ez);\nprint(v); // => vmath.vector3(0, 45, 90)"
|
|
1906
|
+
}
|
|
1907
|
+
],
|
|
1908
|
+
"vmath.rotate": [
|
|
1909
|
+
{
|
|
1910
|
+
"sourceHash": "537daa1275b53d87",
|
|
1911
|
+
"ts": "const vec = vmath.vector3(1, 1, 0);\nconst rot = vmath.quat_rotation_z(3.141592563);\nprint(vmath.rotate(rot, vec)); // => vmath.vector3(-1.0000002384186, -0.99999988079071, 0)"
|
|
1912
|
+
}
|
|
1913
|
+
],
|
|
1914
|
+
"vmath.slerp": [
|
|
1915
|
+
{
|
|
1916
|
+
"sourceHash": "48b2a7e8910d8948",
|
|
1917
|
+
"ts": "export default defineScript({\n init() {\n return { t: 0 };\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startpos = vmath.vector3(0, 600, 0);\n const endpos = vmath.vector3(600, 0, 0);\n const pos = vmath.slerp(self.t, startpos, endpos);\n go.set_position(pos, \"go\");\n }\n },\n});"
|
|
1918
|
+
},
|
|
1919
|
+
{
|
|
1920
|
+
"sourceHash": "858acbd524dfe896",
|
|
1921
|
+
"ts": "export default defineScript({\n init(self) {\n self.t = 0;\n },\n\n update(self, dt) {\n self.t = self.t + dt;\n if (self.t <= 1) {\n const startrot = vmath.quat_rotation_z(0);\n const endrot = vmath.quat_rotation_z(3.141592653);\n const rot = vmath.slerp(self.t, startrot, endrot);\n go.set_rotation(rot, \"go\");\n }\n },\n});"
|
|
1922
|
+
}
|
|
1923
|
+
],
|
|
1924
|
+
"vmath.vector": [
|
|
1925
|
+
{
|
|
1926
|
+
"sourceHash": "63ffad32dfb87144",
|
|
1927
|
+
"ts": "// How to create a vector with custom data to be used for animation easing:\nconst values = [0, 0.5, 0];\nconst vec = vmath.vector(values);\nprint(vec); // => vmath.vector (size: 3)\nprint(vec[2]); // => 0.5"
|
|
1928
|
+
}
|
|
1929
|
+
],
|
|
1930
|
+
"vmath.vector3": [
|
|
1931
|
+
{
|
|
1932
|
+
"sourceHash": "ddcab8eda46d059c",
|
|
1933
|
+
"ts": "const vec = vmath.vector3(1.0, 2.0, 3.0);\nprint(vec); // => vmath.vector3(1, 2, 3)\nprint(vec.unm()); // => vmath.vector3(-1, -2, -3)\nprint(vec.mul(2)); // => vmath.vector3(2, 4, 6)\nprint(vec.add(vmath.vector3(2.0))); // => vmath.vector3(3, 4, 5)\nprint(vec.sub(vmath.vector3(2.0))); // => vmath.vector3(-1, 0, 1)"
|
|
1934
|
+
},
|
|
1935
|
+
{
|
|
1936
|
+
"sourceHash": "458c38e860a884b5",
|
|
1937
|
+
"ts": "const vec = vmath.vector3();\npprint(vec); // => vmath.vector3(0, 0, 0)\nprint(vec.x); // => 0"
|
|
1938
|
+
},
|
|
1939
|
+
{
|
|
1940
|
+
"sourceHash": "9afe6c6c89935d58",
|
|
1941
|
+
"ts": "const vec = vmath.vector3(1.0);\nprint(vec); // => vmath.vector3(1, 1, 1)\nprint(vec.x); // => 1"
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
"sourceHash": "0b3d72f4a0a9719b",
|
|
1945
|
+
"ts": "const vec1 = vmath.vector3(1.0);\nconst vec2 = vmath.vector3(vec1);\nif (vec1 === vec2) {\n // yes, they are equal\n print(vec2); // => vmath.vector3(1, 1, 1)\n}"
|
|
1946
|
+
}
|
|
1947
|
+
],
|
|
1948
|
+
"vmath.vector4": [
|
|
1949
|
+
{
|
|
1950
|
+
"sourceHash": "c98ee6ded6048d17",
|
|
1951
|
+
"ts": "const vec = vmath.vector4(1.0, 2.0, 3.0, 4.0);\nprint(vec); // => vmath.vector4(1, 2, 3, 4)\nprint(vec.unm()); // => vmath.vector4(-1, -2, -3, -4)\nprint(vec.mul(2)); // => vmath.vector4(2, 4, 6, 8)\nprint(vec.add(vmath.vector4(2.0))); // => vmath.vector4(3, 4, 5, 6)\nprint(vec.sub(vmath.vector4(2.0))); // => vmath.vector4(-1, 0, 1, 2)"
|
|
1952
|
+
},
|
|
1953
|
+
{
|
|
1954
|
+
"sourceHash": "9bfbd9336d3b8df4",
|
|
1955
|
+
"ts": "const vec = vmath.vector4();\nprint(vec); // => vmath.vector4(0, 0, 0, 0)\nprint(vec.w); // => 0"
|
|
1956
|
+
},
|
|
1957
|
+
{
|
|
1958
|
+
"sourceHash": "67b29b185a464b2c",
|
|
1959
|
+
"ts": "const vec = vmath.vector4(1.0);\nprint(vec); // => vmath.vector4(1, 1, 1, 1)\nprint(vec.w); // => 1"
|
|
1960
|
+
},
|
|
1961
|
+
{
|
|
1962
|
+
"sourceHash": "4af4b3cb046df045",
|
|
1963
|
+
"ts": "const vec1 = vmath.vector4(1.0);\nconst vec2 = vmath.vector4(vec1);\nif (vec1 === vec2) {\n // yes, they are equal\n print(vec2); // => vmath.vector4(1, 1, 1, 1)\n}"
|
|
1964
|
+
}
|
|
1965
|
+
],
|
|
1966
|
+
"window.set_listener": [
|
|
1967
|
+
{
|
|
1968
|
+
"sourceHash": "5075cb14faa9510b",
|
|
1969
|
+
"ts": "function window_callback(self, event, data) {\n if (event === window.WINDOW_EVENT_FOCUS_LOST) {\n print(\"window.WINDOW_EVENT_FOCUS_LOST\");\n } else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {\n print(\"window.WINDOW_EVENT_FOCUS_GAINED\");\n } else if (event === window.WINDOW_EVENT_ICONFIED) {\n print(\"window.WINDOW_EVENT_ICONFIED\");\n } else if (event === window.WINDOW_EVENT_DEICONIFIED) {\n print(\"window.WINDOW_EVENT_DEICONIFIED\");\n } else if (event === window.WINDOW_EVENT_RESIZED) {\n print(\"Window resized: \", data.width, data.height);\n }\n}\n\nexport default defineScript({\n init() {\n window.set_listener(window_callback);\n },\n});"
|
|
1970
|
+
}
|
|
1971
|
+
],
|
|
1972
|
+
"zlib.deflate": [
|
|
1973
|
+
{
|
|
1974
|
+
"sourceHash": "dbfb4f8f6e58ec2c",
|
|
1975
|
+
"ts": "const data = \"This is a string with uncompressed data.\";\nconst compressed_data = zlib.deflate(data);\nlet s = \"\";\nfor (const c of compressed_data) {\n s = s + \"\\\\\" + c.charCodeAt(0);\n}\nprint(s); //> \\120\\94\\11\\201\\200\\44\\86\\0\\162\\68\\133\\226\\146\\162 ..."
|
|
1976
|
+
}
|
|
1977
|
+
],
|
|
1978
|
+
"zlib.inflate": [
|
|
1979
|
+
{
|
|
1980
|
+
"sourceHash": "6b8b8cc6d9afe679",
|
|
1981
|
+
"ts": "const data = \"\\120\\94\\11\\201\\200\\44\\86\\0\\162\\68\\133\\226\\146\\162\\204\\188\\116\\133\\242\\204\\146\\12\\133\\210\\188\\228\\252\\220\\130\\162\\212\\226\\226\\212\\20\\133\\148\\196\\146\\68\\61\\0\\44\\67\\14\\201\";\nconst uncompressed_data = zlib.inflate(data);\nprint(uncompressed_data); //> This is a string with uncompressed data."
|
|
1982
|
+
}
|
|
1983
|
+
]
|
|
1984
|
+
}
|