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

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

Issue 1161023006: Adds basic support for images in game example (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: git cl status Created 5 years, 6 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
« no previous file with comments | « sky/examples/game/lib/game_world.dart ('k') | sky/examples/game/lib/sprite_box.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 callback) {
15 _images = new Map();
16 _totalNumImages = urls.length;
17 _callback = callback;
18 urls.forEach(_addURL);
19 }
20
21 void _addURL(String url) {
22 image_cache.load(url, (Image image) {
23 // Store reference to image
24 _images[url] = image;
25
26 // Check if all images are loaded
27 _numLoadedImages++;
28 if (_numLoadedImages==_totalNumImages) {
29 // Everything loaded, make callback
30 _callback(this);
31 }
32 });
33 }
34
35 Image getImage(String url) => _images[url];
36
37 Image operator [](String url) => _images[url];
38 }
OLDNEW
« no previous file with comments | « sky/examples/game/lib/game_world.dart ('k') | sky/examples/game/lib/sprite_box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698