Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: sky/examples/game/lib/image_map.dart

Issue 1218593002: Move sky/examples to sky/sdk/lib/example, and code changes to support that change. Fixes T277. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 part of sprites;
2
3 typedef void ImageMapCallback(ImageMap preloader);
4
5 class ImageMap {
6
7 Map<String, Image> _images;
8
9 int _totalNumImages = 0;
10 int _numLoadedImages = 0;
11
12 ImageMapCallback _callback;
13
14 ImageMap(List<String> urls, ImageMapCallback this._callback) {
15 _images = new Map();
16 _totalNumImages = urls.length;
17 urls.forEach(_addURL);
18 }
19
20 void _addURL(String url) {
21 image_cache.load(url, (Image image) {
22 // Store reference to image
23 _images[url] = image;
24
25 // Check if all images are loaded
26 _numLoadedImages++;
27 if (_numLoadedImages==_totalNumImages) {
28 // Everything loaded, make callback
29 _callback(this);
30 }
31 });
32 }
33
34 Image getImage(String url) => _images[url];
35
36 Image operator [](String url) => _images[url];
37 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698