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

Unified Diff: sky/examples/game/lib/image_map.dart

Issue 1149183004: Sky example game enhancements, adds preloading of images and adds transform modes to SpriteBox (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fixes setting parameter with sugar Created 5 years, 7 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/game/lib/image_map.dart
diff --git a/sky/examples/game/lib/image_map.dart b/sky/examples/game/lib/image_map.dart
new file mode 100644
index 0000000000000000000000000000000000000000..577df2a4e0bf10dbd933f14da08ae7171f02a56c
--- /dev/null
+++ b/sky/examples/game/lib/image_map.dart
@@ -0,0 +1,37 @@
+part of sprites;
+
+typedef void ImageMapCallback(ImageMap preloader);
+
+class ImageMap {
+
+ Map<String, Image> _images;
+
+ int _totalNumImages = 0;
+ int _numLoadedImages = 0;
+
+ ImageMapCallback _callback;
+
+ ImageMap(List<String> urls, ImageMapCallback this._callback) {
+ _images = new Map();
+ _totalNumImages = urls.length;
+ urls.forEach(_addURL);
+ }
+
+ void _addURL(String url) {
+ image_cache.load(url, (Image image) {
+ // Store reference to image
+ _images[url] = image;
+
+ // Check if all images are loaded
+ _numLoadedImages++;
+ if (_numLoadedImages==_totalNumImages) {
+ // Everything loaded, make callback
+ _callback(this);
+ }
+ });
+ }
+
+ Image getImage(String url) => _images[url];
+
+ Image operator [](String url) => _images[url];
+}
« 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