Skip to content

Commit 1d9f2d3

Browse files
committed
Merge branch 'master' of https://github.com/defold/examples
2 parents c3d6c02 + e9bc302 commit 1d9f2d3

File tree

14 files changed

+370
-47
lines changed

14 files changed

+370
-47
lines changed

input/entity_picking/example/camera_math.lua

Lines changed: 0 additions & 42 deletions
This file was deleted.

input/entity_picking/example/entity_picking.script

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
local camera_math = require("example.camera_math")
1+
go.property("camera_url", msg.url("/camera#camera"))
22

33
--- Performs a raycast from the camera through a screen position to find an entity.
4+
-- @param camera_url url The camera URL to use for screen-to-world conversion
45
-- @param screen_x number The x-coordinate on the screen
56
-- @param screen_y number The y-coordinate on the screen
67
-- @param collision_groups table The collision groups to check against as array of hash values
78
-- @return table|nil The first entity hit by the ray, or nil if nothing was hit
8-
local function pick_entity(screen_x, screen_y, collision_groups)
9-
local from = camera_math.screen_to_world(screen_x, screen_y, 0, "/camera#camera")
10-
local to = camera_math.screen_to_world(screen_x, screen_y, 100, "/camera#camera")
9+
local function pick_entity(camera_url, screen_x, screen_y, collision_groups)
10+
local from = camera.screen_to_world(vmath.vector3(screen_x, screen_y, 0), camera_url)
11+
local to = camera.screen_to_world(vmath.vector3(screen_x, screen_y, 100), camera_url)
1112
local results = physics.raycast(from, to, collision_groups, { all = false })
1213
if not results then
1314
return nil
@@ -34,7 +35,7 @@ function update(self, dt)
3435
return
3536
end
3637

37-
local result = pick_entity(self.last_input.screen_x, self.last_input.screen_y, { hash("target") })
38+
local result = pick_entity(self.camera_url, self.last_input.screen_x, self.last_input.screen_y, { hash("target") })
3839
if result then
3940
-- Store in the result table the model URL of the entity just for convenience
4041
result.model_url = msg.url(nil, result.id, "model")
5.24 KB
Loading
2.99 KB
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
font: "/builtins/fonts/vera_mo_bd.ttf"
2+
material: "/builtins/fonts/font-df.material"
3+
size: 50
4+
outline_alpha: 1.0
5+
outline_width: 5.0
6+
shadow_alpha: 1.0
7+
shadow_y: -4.0
8+
output_format: TYPE_DISTANCE_FIELD
9+
render_mode: MODE_MULTI_LAYER
10+
characters: " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
images {
2+
image: "/assets/coin_06.png"
3+
}
4+
extrude_borders: 2
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
tags: material
3+
title: Repeating Background
4+
brief: Create a scrolling background using a repeating texture on a model quad.
5+
author: Artsiom Trubchyk
6+
scripts: repeating_background.script, repeating_background.vp, repeating_background.fp
7+
thumbnail: thumbnail.png
8+
---
9+
10+
A repeating, scrolling texture can add visual interest to a static background. This example demonstrates how to create an infinitely tiling background using a model quad with a repeating texture. The effect is achieved by scrolling the UV coordinates over time, creating smooth, continuous motion.
11+
12+
The script driving the effect works as follows:
13+
14+
* Each frame it reads the current window size and scales the `background` game object so the quad covers the full viewport. The rotation is set via `euler.z` (Rotation Z in the IDE).
15+
* It converts the window size into a UV repeat scale (`uv_params.x/y`) so the texture tiles across the screen.
16+
* It advances a scrolling offset based on `scroll_speed` and `tile_size`, wraps it to the 0..1 range, and sends `uv_params` to the model material.
17+
18+
The asset used in this example is from Kenney's [Puzzle Pack 2](https://www.kenney.nl/assets/puzzle-pack-2), licensed under CC0.
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
name: "repeating_background"
2+
scale_along_z: 0
3+
embedded_instances {
4+
id: "background"
5+
data: "components {\n"
6+
" id: \"repeating_background\"\n"
7+
" component: \"/example/repeating_background.script\"\n"
8+
"}\n"
9+
"embedded_components {\n"
10+
" id: \"model\"\n"
11+
" type: \"model\"\n"
12+
" data: \"mesh: \\\"/builtins/assets/meshes/quad.dae\\\"\\n"
13+
"name: \\\"{{NAME}}\\\"\\n"
14+
"materials {\\n"
15+
" name: \\\"default\\\"\\n"
16+
" material: \\\"/example/repeating_background.material\\\"\\n"
17+
" textures {\\n"
18+
" sampler: \\\"texture0\\\"\\n"
19+
" texture: \\\"/assets/bg_icon.png\\\"\\n"
20+
" }\\n"
21+
"}\\n"
22+
"\"\n"
23+
"}\n"
24+
""
25+
rotation {
26+
z: 0.13052619
27+
w: 0.9914449
28+
}
29+
scale3 {
30+
x: 512.0
31+
y: 512.0
32+
}
33+
}
34+
embedded_instances {
35+
id: "camera"
36+
data: "embedded_components {\n"
37+
" id: \"camera\"\n"
38+
" type: \"camera\"\n"
39+
" data: \"aspect_ratio: 1.0\\n"
40+
"fov: 0.7854\\n"
41+
"near_z: -1.0\\n"
42+
"far_z: 1.0\\n"
43+
"orthographic_projection: 1\\n"
44+
"\"\n"
45+
"}\n"
46+
""
47+
}
48+
embedded_instances {
49+
id: "ui"
50+
data: "embedded_components {\n"
51+
" id: \"label1\"\n"
52+
" type: \"label\"\n"
53+
" data: \"size {\\n"
54+
" x: 512.0\\n"
55+
" y: 60.0\\n"
56+
"}\\n"
57+
"text: \\\"YOU EARNED\\\"\\n"
58+
"font: \\\"/assets/custom.font\\\"\\n"
59+
"material: \\\"/builtins/fonts/label-df.material\\\"\\n"
60+
"\"\n"
61+
" position {\n"
62+
" y: 187.0\n"
63+
" z: 0.1\n"
64+
" }\n"
65+
" scale {\n"
66+
" x: 0.75\n"
67+
" y: 0.75\n"
68+
" }\n"
69+
"}\n"
70+
"embedded_components {\n"
71+
" id: \"label2\"\n"
72+
" type: \"label\"\n"
73+
" data: \"size {\\n"
74+
" x: 512.0\\n"
75+
" y: 60.0\\n"
76+
"}\\n"
77+
"text: \\\"999 COINS!\\\"\\n"
78+
"font: \\\"/assets/custom.font\\\"\\n"
79+
"material: \\\"/builtins/fonts/label-df.material\\\"\\n"
80+
"\"\n"
81+
" position {\n"
82+
" y: -169.0\n"
83+
" z: 0.1\n"
84+
" }\n"
85+
"}\n"
86+
"embedded_components {\n"
87+
" id: \"coin3\"\n"
88+
" type: \"sprite\"\n"
89+
" data: \"default_animation: \\\"coin_06\\\"\\n"
90+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
91+
"size {\\n"
92+
" x: 96.0\\n"
93+
" y: 96.0\\n"
94+
"}\\n"
95+
"size_mode: SIZE_MODE_MANUAL\\n"
96+
"textures {\\n"
97+
" sampler: \\\"texture_sampler\\\"\\n"
98+
" texture: \\\"/assets/sprites.atlas\\\"\\n"
99+
"}\\n"
100+
"\"\n"
101+
" position {\n"
102+
" x: 20.0\n"
103+
" y: 41.0\n"
104+
" z: 0.1\n"
105+
" }\n"
106+
"}\n"
107+
"embedded_components {\n"
108+
" id: \"coin1\"\n"
109+
" type: \"sprite\"\n"
110+
" data: \"default_animation: \\\"coin_06\\\"\\n"
111+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
112+
"size {\\n"
113+
" x: 96.0\\n"
114+
" y: 96.0\\n"
115+
"}\\n"
116+
"size_mode: SIZE_MODE_MANUAL\\n"
117+
"textures {\\n"
118+
" sampler: \\\"texture_sampler\\\"\\n"
119+
" texture: \\\"/assets/sprites.atlas\\\"\\n"
120+
"}\\n"
121+
"\"\n"
122+
" position {\n"
123+
" x: -41.0\n"
124+
" y: 15.0\n"
125+
" z: 0.1\n"
126+
" }\n"
127+
"}\n"
128+
"embedded_components {\n"
129+
" id: \"coin2\"\n"
130+
" type: \"sprite\"\n"
131+
" data: \"default_animation: \\\"coin_06\\\"\\n"
132+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
133+
"size {\\n"
134+
" x: 96.0\\n"
135+
" y: 96.0\\n"
136+
"}\\n"
137+
"size_mode: SIZE_MODE_MANUAL\\n"
138+
"textures {\\n"
139+
" sampler: \\\"texture_sampler\\\"\\n"
140+
" texture: \\\"/assets/sprites.atlas\\\"\\n"
141+
"}\\n"
142+
"\"\n"
143+
" position {\n"
144+
" x: 6.0\n"
145+
" y: -30.0\n"
146+
" z: 0.1\n"
147+
" }\n"
148+
"}\n"
149+
"embedded_components {\n"
150+
" id: \"glow\"\n"
151+
" type: \"sprite\"\n"
152+
" data: \"default_animation: \\\"anim\\\"\\n"
153+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
154+
"size {\\n"
155+
" x: 600.0\\n"
156+
" y: 600.0\\n"
157+
"}\\n"
158+
"size_mode: SIZE_MODE_MANUAL\\n"
159+
"textures {\\n"
160+
" sampler: \\\"texture_sampler\\\"\\n"
161+
" texture: \\\"/builtins/graphics/particle_blob.tilesource\\\"\\n"
162+
"}\\n"
163+
"\"\n"
164+
"}\n"
165+
""
166+
position {
167+
z: 0.5
168+
}
169+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#version 140
2+
3+
in mediump vec2 var_texcoord0;
4+
5+
out vec4 out_fragColor;
6+
7+
uniform mediump sampler2D texture0;
8+
9+
void main()
10+
{
11+
out_fragColor = texture(texture0, var_texcoord0);
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "repeating_background"
2+
tags: "model"
3+
vertex_program: "/example/repeating_background.vp"
4+
fragment_program: "/example/repeating_background.fp"
5+
vertex_space: VERTEX_SPACE_WORLD
6+
vertex_constants {
7+
name: "mtx_worldview"
8+
type: CONSTANT_TYPE_WORLDVIEW
9+
}
10+
vertex_constants {
11+
name: "mtx_proj"
12+
type: CONSTANT_TYPE_PROJECTION
13+
}
14+
vertex_constants {
15+
name: "uv_params"
16+
type: CONSTANT_TYPE_USER
17+
value {
18+
x: 1.0
19+
y: 1.0
20+
z: 0.0
21+
w: 0.0
22+
}
23+
}
24+
samplers {
25+
name: "texture0"
26+
wrap_u: WRAP_MODE_REPEAT
27+
wrap_v: WRAP_MODE_REPEAT
28+
filter_min: FILTER_MODE_MIN_LINEAR
29+
filter_mag: FILTER_MODE_MAG_LINEAR
30+
max_anisotropy: 0.0
31+
}

0 commit comments

Comments
 (0)