Skip to content

Commit 2332b6b

Browse files
authored
Added animation delay example. (#170)
1 parent ea19c17 commit 2332b6b

9 files changed

Lines changed: 214 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
path_settings {
2+
path: "**"
3+
profile: "Default"
4+
}
5+
profiles {
6+
name: "Default"
7+
platforms {
8+
os: OS_ID_GENERIC
9+
formats {
10+
format: TEXTURE_FORMAT_RGBA
11+
compression_level: BEST
12+
compression_type: COMPRESSION_TYPE_DEFAULT
13+
}
14+
mipmaps: false
15+
max_texture_size: 0
16+
premultiply_alpha: true
17+
}
18+
}
13.8 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
images {
2+
image: "/assets/images/logo-color.png"
3+
}
4+
extrude_borders: 2
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
tags: animation, delay
3+
title: Animation Delay - Wave
4+
brief: This example shows how to use the delay parameter of `go.animate()` to create a wave effect.
5+
author: Defold Foundation
6+
scripts: animation_delay.script
7+
thumbnail: thumbnail.png
8+
---
9+
10+
This example shows how to use the `delay` parameter of `go.animate()` (or `gui.animate()`) to create a wave effect.
11+
12+
## Setup
13+
14+
The collection contains four game objects aligned in a row next to each other. The additional `controller` game object has the script that starts one animation for each sprite.
15+
16+
![setup](setup.png)
17+
18+
## How It Works
19+
20+
Four game objects start the same `position.y` ping-pong animation, but each one begins slightly later than the previous sprite. The result is a simple wave that makes the `delay` argument easy to see.
21+
22+
The script stores the four target URLs in a table and loops over them with `ipairs()`. Each call to `go.animate()` uses the same target value, easing, duration, and playback mode.
23+
24+
The only thing that changes per sprite is the argument: `delay`. Multiplying the sprite index by `0.15` seconds offsets each start time just enough to produce a clear staggered wave.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: "default"
2+
scale_along_z: 0
3+
embedded_instances {
4+
id: "ship_1"
5+
data: "embedded_components {\n"
6+
" id: \"sprite\"\n"
7+
" type: \"sprite\"\n"
8+
" data: \"default_animation: \\\"logo-color\\\"\\n"
9+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
10+
"textures {\\n"
11+
" sampler: \\\"texture_sampler\\\"\\n"
12+
" texture: \\\"/assets/sprites.atlas\\\"\\n"
13+
"}\\n"
14+
"\"\n"
15+
"}\n"
16+
""
17+
position {
18+
x: 120.0
19+
y: 180.0
20+
}
21+
}
22+
embedded_instances {
23+
id: "ship_2"
24+
data: "embedded_components {\n"
25+
" id: \"sprite\"\n"
26+
" type: \"sprite\"\n"
27+
" data: \"default_animation: \\\"logo-color\\\"\\n"
28+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
29+
"textures {\\n"
30+
" sampler: \\\"texture_sampler\\\"\\n"
31+
" texture: \\\"/assets/sprites.atlas\\\"\\n"
32+
"}\\n"
33+
"\"\n"
34+
"}\n"
35+
""
36+
position {
37+
x: 280.0
38+
y: 180.0
39+
}
40+
}
41+
embedded_instances {
42+
id: "ship_3"
43+
data: "embedded_components {\n"
44+
" id: \"sprite\"\n"
45+
" type: \"sprite\"\n"
46+
" data: \"default_animation: \\\"logo-color\\\"\\n"
47+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
48+
"textures {\\n"
49+
" sampler: \\\"texture_sampler\\\"\\n"
50+
" texture: \\\"/assets/sprites.atlas\\\"\\n"
51+
"}\\n"
52+
"\"\n"
53+
"}\n"
54+
""
55+
position {
56+
x: 440.0
57+
y: 180.0
58+
}
59+
}
60+
embedded_instances {
61+
id: "ship_4"
62+
data: "embedded_components {\n"
63+
" id: \"sprite\"\n"
64+
" type: \"sprite\"\n"
65+
" data: \"default_animation: \\\"logo-color\\\"\\n"
66+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
67+
"textures {\\n"
68+
" sampler: \\\"texture_sampler\\\"\\n"
69+
" texture: \\\"/assets/sprites.atlas\\\"\\n"
70+
"}\\n"
71+
"\"\n"
72+
"}\n"
73+
""
74+
position {
75+
x: 600.0
76+
y: 180.0
77+
}
78+
}
79+
embedded_instances {
80+
id: "controller"
81+
data: "components {\n"
82+
" id: \"script\"\n"
83+
" component: \"/example/animation_delay.script\"\n"
84+
"}\n"
85+
""
86+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local TARGET_URLS = { "/ship_1", "/ship_2", "/ship_3", "/ship_4" } -- <1>
2+
local WAVE_HEIGHT = 420 -- <2>
3+
local STEP_DELAY = 0.15
4+
5+
function init(self)
6+
for i, url in ipairs(TARGET_URLS) do -- <3>
7+
go.animate(url, "position.y", go.PLAYBACK_LOOP_PINGPONG, WAVE_HEIGHT, go.EASING_INOUTSINE, 1.2, i * STEP_DELAY) -- <4>
8+
end
9+
end
10+
11+
--[[
12+
1. The script animates the four game objects with sprites and in table we put the paths for the ships in the same collection.
13+
2. All ships move to the same target peak Y value, and the wave is created by timing.
14+
3. Loop over the four sprite game objects that should be animated.
15+
4. Start the same ping-pong animation on each game object, but set the seventh `go.animate()` argument (`delay`) to `i * 0.15`. That staggered start time creates the wave effect.
16+
]]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[project]
2+
title = Animation Delay
3+
version = 0.1
4+
developer = Defold Foundation
5+
6+
[bootstrap]
7+
main_collection = /example/animation_delay.collectionc
8+
9+
[input]
10+
game_binding = /builtins/input/all.input_bindingc
11+
repeat_interval = 0.05
12+
13+
[display]
14+
width = 720
15+
height = 720
16+
high_dpi = 1
17+
18+
[physics]
19+
scale = 0.02
20+
gravity_y = -500.0
21+
22+
[script]
23+
shared_state = 1
24+
25+
[collection_proxy]
26+
max_count = 256
27+
28+
[label]
29+
subpixels = 1
30+
31+
[sprite]
32+
subpixels = 1
33+
max_count = 32765
34+
35+
[windows]
36+
iap_provider =
37+
38+
[android]
39+
package = com.defold.examples
40+
41+
[ios]
42+
bundle_identifier = com.defold.examples
43+
44+
[osx]
45+
bundle_identifier = com.defold.examples
46+
47+
[html5]
48+
show_fullscreen_button = 0
49+
show_made_with_defold = 0
50+
scale_mode = no_scale
51+
heap_size = 64
52+
53+
[graphics]
54+
texture_profiles = /all.texture_profiles
55+
56+
[collection]
57+
max_instances = 32765
58+
59+
[particle_fx]
60+
max_emitter_count = 1024
61+
62+
[render]
63+
clear_color_blue = 0.183594
64+
clear_color_green = 0.164063
65+
clear_color_red = 0.160156
66+
136 KB
Loading
72 KB
Loading

0 commit comments

Comments
 (0)