@@ -11,28 +11,39 @@ function init(self)
1111 local maxx = 4
1212
1313 self.urls = {}
14+
15+ -- 1. For all sprites in the example we set a slightly different `mycolor` vertex attribute:
1416 for y = 0, maxy do
1517 for x = 0, maxx do
1618 local p = vmath.vector3(startx + x*spacingx, starty + y*spacingy, 0.5)
1719 local id = factory.create("#factory", p, nil, nil, vmath.vector3(0.8, 0.8, 1))
1820 local url = msg.url(nil, id, "sprite")
1921 table.insert(self.urls, url)
20-
22+
23+ -- set vertex attribute:
2124 go.set(url, "mycolor", vmath.vector4(x/maxx, y/maxy, 0, 1))
2225 end
2326 end
2427
2528 self.updated = false
29+ self.animation_finished = true
2630end
2731
2832function update(self, dt)
2933 self.updated = true
3034end
3135
3236function on_input(self, action_id, action)
33- if action_id == hash("touch") and action.pressed and self.updated then
37+
38+ -- 2. On click we animate the `mycolor` vertex attribute of each of the sprites to blue and back.
39+ if action_id == hash("touch") and action.pressed and self.updated and self.animation_finished then
3440 for _, url in ipairs(self.urls) do
35- go.animate(url, "mycolor", go.PLAYBACK_ONCE_PINGPONG, vmath.vector4(0, 0, 1, 1), go.EASING_LINEAR, .2)
41+ self.animation_finished = false
42+
43+ -- animate vertex attribute:
44+ go.animate(url, "mycolor", go.PLAYBACK_ONCE_PINGPONG, vmath.vector4(0, 0, 1, 1), go.EASING_LINEAR, 1, 0, function()
45+ self.animation_finished = true
46+ end)
3647 end
3748 end
3849end
0 commit comments