Skip to content
This repository
Browse code

easier local development

  • Loading branch information...
commit bb2e123329fb553c92cf16018d6b3a7f135abb56 1 parent b6f625a
Diederick Lawson authored December 13, 2011

Showing 40 changed files with 1,296 additions and 59 deletions. Show diff stats Hide diff stats

  1. 1  .rvmrc
  2. 5  Gemfile
  3. 22  Gemfile.lock
  4. 4  Guardfile
  5. 47  README.rdoc
  6. 22  demos/demo.coffee
  7. 47  demos/demo.js
  8. 2  dev_demos_start
  9. 2  dev_start
  10. 2  lib/ansii_palette.js
  11. 32  lib/bitmap.js
  12. 22  lib/display_container.js
  13. 53  lib/display_container_mixin.js
  14. 112  lib/display_object.js
  15. 12  lib/ease_default.js
  16. 81  lib/pixel_sprite.js
  17. 60  lib/renderer.js
  18. 182  lib/shape.js
  19. 24  lib/sprite.js
  20. 124  lib/stacked_loader.js
  21. 225  lib/stage.js
  22. 42  lib/text_field.js
  23. 81  lib/tween.js
  24. 50  lib/tween_command.js
  25. 56  lib/utils.js
  26. 3  src/bitmap.coffee
  27. 3  src/display_container.coffee
  28. 3  src/display_container_mixin.coffee
  29. 3  src/display_object.coffee
  30. 3  src/ease_default.coffee
  31. 3  src/pixel_sprite.coffee
  32. 3  src/renderer.coffee
  33. 3  src/shape.coffee
  34. 3  src/sprite.coffee
  35. 3  src/stacked_loader.coffee
  36. 3  src/stage.coffee
  37. 3  src/text_field.coffee
  38. 3  src/tween.coffee
  39. 3  src/tween_command.coffee
  40. 3  src/utils.coffee
1  .rvmrc
... ...
@@ -0,0 +1 @@
  1
+rvm 1.9.3@canvas_library --create
5  Gemfile
... ...
@@ -0,0 +1,5 @@
  1
+source :rubygems
  2
+
  3
+group :development do
  4
+  gem 'guard-coffeescript'
  5
+end
22  Gemfile.lock
... ...
@@ -0,0 +1,22 @@
  1
+GEM
  2
+  remote: http://rubygems.org/
  3
+  specs:
  4
+    coffee-script (2.2.0)
  5
+      coffee-script-source
  6
+      execjs
  7
+    coffee-script-source (1.1.3)
  8
+    execjs (1.2.12)
  9
+      multi_json (~> 1.0)
  10
+    guard (0.8.8)
  11
+      thor (~> 0.14.6)
  12
+    guard-coffeescript (0.5.2)
  13
+      coffee-script (>= 2.2.0)
  14
+      guard (>= 0.8.3)
  15
+    multi_json (1.0.4)
  16
+    thor (0.14.6)
  17
+
  18
+PLATFORMS
  19
+  ruby
  20
+
  21
+DEPENDENCIES
  22
+  guard-coffeescript
4  Guardfile
... ...
@@ -0,0 +1,4 @@
  1
+#!/usr/bin/ruby
  2
+#
  3
+guard 'coffeescript', :input => 'demos'
  4
+guard 'coffeescript', :input => 'src', :output => 'lib'
47  README.rdoc
Source Rendered
@@ -15,10 +15,10 @@ HTML:
15 15
 Coffeescript:
16 16
   run = ->
17 17
     # this is the screen
18  
-    stage = new Stage('test_canvas')
  18
+    stage = new CanvasLibrary.Stage('test_canvas')
19 19
 
20 20
     # create a rectangle
21  
-    someShape = new Shape()
  21
+    someShape = new CanvasLibrary.Shape()
22 22
     someShape.x = 0
23 23
     someShape.y = 0
24 24
 
@@ -26,7 +26,7 @@ Coffeescript:
26 26
     someShape.fillRect 0, 0, 50, 50
27 27
 
28 28
     # create another rectangle
29  
-    otherShape = new Shape()
  29
+    otherShape = new CanvasLibrary.Shape()
30 30
     otherShape.alpha = .5
31 31
     otherShape.fillStyle 'rgba(255, 0, 0, 1)'
32 32
     otherShape.fillRect 0, 0, 25, 25
@@ -39,7 +39,7 @@ Coffeescript:
39 39
     stage.addChild otherShape
40 40
 
41 41
     # setup renderer and connect it to the stage and run at 25 fps
42  
-    renderer = new Renderer(stage, 25)
  42
+    renderer = new CanvasLibrary.Renderer(stage, 25)
43 43
     renderer.run()
44 44
 
45 45
     # tween some stuff
@@ -55,17 +55,17 @@ A DisplayContainer is an object that can hold other graphical objects. These gra
55 55
 The +x+ and +y+ position of graphical objects are relative and are translated to canvas +x+ and +y+ positions during the rendering process. This rendering process can be triggered by calling the +draw+ function on any displaycontainer.
56 56
 
57 57
 Nesting objects:
58  
-  obj = new Shape()
  58
+  obj = new CanvasLibrary.Shape()
59 59
   obj.x = 10
60 60
   obj.y = 10
61 61
 
62  
-  otherObj = new Shape()
  62
+  otherObj = new CanvasLibrary.Shape()
63 63
   otherObj.x = 0
64 64
   otherObj.y = 0
65 65
 
66 66
   obj.addChild otherObj
67 67
 
68  
-  yetAnotherObj = new Shape()
  68
+  yetAnotherObj = new CanvasLibrary.Shape()
69 69
   yetAnotherObj.x = 0
70 70
   yetAnotherObj.y = 0
71 71
 
@@ -80,9 +80,9 @@ Note: The stage is the main screen. This object also acts as an DisplayContainer
80 80
 The drawing API is almost the same as the Canvas drawing API. If you want to draw paths to the canvas, use the +Shape+ class.
81 81
 
82 82
 Drawing rectangles:
83  
-  stage = new Stage("the_screen");
  83
+  stage = new CanvasLibrary.Stage("the_screen");
84 84
 
85  
-  rect = new Shape()
  85
+  rect = new CanvasLibrary.Shape()
86 86
   rect.x = 0
87 87
   rect.y = 0
88 88
   rect.fillStyle "rgb(255, 0, 0, 1)"
@@ -97,14 +97,14 @@ Drawing rectangles:
97 97
 == Loading and drawing bitmaps
98 98
 
99 99
 Bitmaps can easily be loaded with the +canavaslib.StackedLoader+ class. The +StackedLoader+ manages all your assets so you can preload images or audio assets before rendering all your stuff.
100  
-  screen = new Stage("the_screen")
  100
+  screen = new CanvasLibrary.Stage("the_screen")
101 101
 
102  
-  StackedLoader.add "image_id", "image", "logo.png"
103  
-  StackedLoader.add "another_image", "image", "foo.png"
104  
-  StackedLoader.add "and_another_one", "image", "bar.png"
  102
+  CanvasLibrary.StackedLoader.add "image_id", "image", "logo.png"
  103
+  CanvasLibrary.StackedLoader.add "another_image", "image", "foo.png"
  104
+  CanvasLibrary.StackedLoader.add "and_another_one", "image", "bar.png"
105 105
 
106  
-  StackedLoader.load =>
107  
-    bitmap = StackedLoader.get "image_id"
  106
+  CanvasLibrary.StackedLoader.load =>
  107
+    bitmap = CanvasLibrary.StackedLoader.get "image_id"
108 108
 
109 109
     screen.addChild bitmap
110 110
     screen.render
@@ -116,7 +116,7 @@ The +load+ function adds an asset to the loadstack. The +start+ function trigger
116 116
 You can use the +Tween+ class to tween objects between two points.
117 117
 
118 118
   ...
119  
-  renderer = new Renderer(stage);
  119
+  renderer = new CanvasLibrary.Renderer(stage);
120 120
   renderer.run 25
121 121
 
122 122
   ...
@@ -143,7 +143,7 @@ Example of tween and mouse interaction:
143 143
 
144 144
 == Pixel fun
145 145
 
146  
-  pixels = new PixelSprite()
  146
+  pixels = new CanvasLibrary.PixelSprite()
147 147
   pixels.drawPixel 0, 0, 'rgba(128, 128, 128, 1)'
148 148
   pixels.drawPixel 1, 0, 'rgba(128, 128, 128, 1)'
149 149
   pixels.drawPixel 2, 0, 'rgba(128, 128, 128, 1)'
@@ -157,12 +157,19 @@ Example of tween and mouse interaction:
157 157
 
158 158
 Or even better, load a retro sprite file!
159 159
 
160  
-  StackedLoader.add 'logo', 'sprite', 'logo.spr'
  160
+  CanvasLibrary.StackedLoader.add 'logo', 'sprite', 'logo.spr'
161 161
 
162  
-  StackedLoader.load =>
163  
-    logo = StackedLoader.get 'logo'
  162
+  CanvasLibrary.StackedLoader.load =>
  163
+    logo = CanvasLibrary.StackedLoader.get 'logo'
164 164
     screen.addChild logo
165 165
 
  166
+== Development
  167
+
  168
+Want to extend the library? If you are using rvm that should be a breeze!
  169
+
  170
+  bundle install
  171
+  guard
  172
+
166 173
 = License and credits
167 174
 Use it and have fun with it! Comments, cakes and hugs are welcome! Just stick to the license!
168 175
 
22  demos/demo.coffee
... ...
@@ -1,11 +1,11 @@
1 1
 run = ->
2 2
   # this is the screen
3  
-  stage = new Stage('test_canvas')
  3
+  stage = new CanvasLibrary.Stage('test_canvas')
4 4
 
5 5
   logo = null
6 6
 
7 7
   # create a rectangle
8  
-  someShape = new Shape()
  8
+  someShape = new CanvasLibrary.Shape()
9 9
   someShape.id = "someShape"
10 10
   someShape.x = 0
11 11
   someShape.y = 0
@@ -14,7 +14,7 @@ run = ->
14 14
   someShape.fillRect 0, 0, 50, 50
15 15
 
16 16
   # create another rectangle
17  
-  otherShape = new Shape()
  17
+  otherShape = new CanvasLibrary.Shape()
18 18
   otherShape.id = "otherShape"
19 19
   otherShape.alpha = .5
20 20
   otherShape.fillStyle 'rgba(255, 0, 0, 1)'
@@ -32,7 +32,7 @@ run = ->
32 32
     Tween.to otherShape, 500, { scaleX: 1, scaleY: 1 }
33 33
 
34 34
   # make this shape follow the mouse
35  
-  mouseShape = new Shape()
  35
+  mouseShape = new CanvasLibrary.Shape()
36 36
   mouseShape.id = "mouseShape"
37 37
   mouseShape.beginPath()
38 38
   mouseShape.fillStyle 'rgba(255, 0, 0, 1)'
@@ -48,7 +48,7 @@ run = ->
48 48
     mouseShape.y = stage.mouseY
49 49
 
50 50
   # some text
51  
-  text = new TextField()
  51
+  text = new CanvasLibrary.TextField()
52 52
   text.id = "text"
53 53
   text.mouseEnabled = true
54 54
   text.useHandCursor = true
@@ -67,16 +67,16 @@ run = ->
67 67
       Tween.kill logo
68 68
       Tween.to logo, 500, { x: stage.mouseX, y: stage.mouseY }
69 69
 
70  
-  moreShapes = new Sprite()
  70
+  moreShapes = new CanvasLibrary.Sprite()
71 71
   moreShapes.x = 0
72 72
   moreShapes.y = 0
73 73
 
74  
-  moreShape1 = new Shape()
  74
+  moreShape1 = new CanvasLibrary.Shape()
75 75
   moreShape1.id = "moreShape1"
76 76
   moreShape1.fillStyle 'rgba(0, 255, 0, 1)'
77 77
   moreShape1.fillRect 0, 0, 50, 50
78 78
 
79  
-  moreShape2 = new Shape()
  79
+  moreShape2 = new CanvasLibrary.Shape()
80 80
   moreShape2.x = 10
81 81
   moreShape2.y = 10
82 82
   moreShape2.fillStyle 'rgba(0, 255, 255, 1)'
@@ -95,7 +95,6 @@ run = ->
95 95
 
96 96
   # load an external bitmap
97 97
   StackedLoader.add 'logo', 'bitmap', 'logo.png'
98  
-  #StackedLoader.add 'sprite', 'sprite', 'logo.spr'
99 98
 
100 99
   StackedLoader.load ->
101 100
     logo = StackedLoader.get('logo')
@@ -104,11 +103,8 @@ run = ->
104 103
     logo.alpha = 0
105 104
     Tween.to logo, 10000, { alpha: 1 }
106 105
 
107  
-    #sprite = StackerLoader.get('sprite')
108  
-    #stage.addChild sprite
109  
-
110 106
   # setup renderer and connect it to the stage and run at 25 fps
111  
-  renderer = new Renderer(stage, 25)
  107
+  renderer = new CanvasLibrary.Renderer(stage, 25)
112 108
   renderer.run()
113 109
 
114 110
   # tween some stuff
47  demos/demo.js
... ...
@@ -1,17 +1,18 @@
1 1
 (function() {
2 2
   var run;
3  
-  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  3
+
4 4
   run = function() {
5 5
     var logo, moreShape1, moreShape2, moreShapes, mouseShape, otherShape, renderer, someShape, stage, text;
6  
-    stage = new Stage('test_canvas');
  6
+    var _this = this;
  7
+    stage = new CanvasLibrary.Stage('test_canvas');
7 8
     logo = null;
8  
-    someShape = new Shape();
  9
+    someShape = new CanvasLibrary.Shape();
9 10
     someShape.id = "someShape";
10 11
     someShape.x = 0;
11 12
     someShape.y = 0;
12 13
     someShape.fillStyle('rgba(0, 0, 0, 1)');
13 14
     someShape.fillRect(0, 0, 50, 50);
14  
-    otherShape = new Shape();
  15
+    otherShape = new CanvasLibrary.Shape();
15 16
     otherShape.id = "otherShape";
16 17
     otherShape.alpha = .5;
17 18
     otherShape.fillStyle('rgba(255, 0, 0, 1)');
@@ -21,19 +22,19 @@
21 22
     otherShape.scaleX = 1;
22 23
     otherShape.scaleY = 1;
23 24
     otherShape.mouseEnabled = true;
24  
-    otherShape.onMouseOver = __bind(function() {
  25
+    otherShape.onMouseOver = function() {
25 26
       return Tween.to(otherShape, 500, {
26 27
         scaleX: 2,
27 28
         scaleY: 2
28 29
       });
29  
-    }, this);
30  
-    otherShape.onMouseOut = __bind(function() {
  30
+    };
  31
+    otherShape.onMouseOut = function() {
31 32
       return Tween.to(otherShape, 500, {
32 33
         scaleX: 1,
33 34
         scaleY: 1
34 35
       });
35  
-    }, this);
36  
-    mouseShape = new Shape();
  36
+    };
  37
+    mouseShape = new CanvasLibrary.Shape();
37 38
     mouseShape.id = "mouseShape";
38 39
     mouseShape.beginPath();
39 40
     mouseShape.fillStyle('rgba(255, 0, 0, 1)');
@@ -42,24 +43,24 @@
42 43
     mouseShape.fill();
43 44
     mouseShape.x = 300;
44 45
     mouseShape.y = 300;
45  
-    stage.onMouseMove = __bind(function() {
  46
+    stage.onMouseMove = function() {
46 47
       mouseShape.x = stage.mouseX;
47 48
       return mouseShape.y = stage.mouseY;
48  
-    }, this);
49  
-    text = new TextField();
  49
+    };
  50
+    text = new CanvasLibrary.TextField();
50 51
     text.id = "text";
51 52
     text.mouseEnabled = true;
52 53
     text.useHandCursor = true;
53 54
     text.text = "canvas_library demo";
54 55
     text.x = 10;
55 56
     text.y = 450;
56  
-    text.onMouseOver = __bind(function() {
  57
+    text.onMouseOver = function() {
57 58
       return text.fillStyle = 'rgba(255, 0, 0, 1)';
58  
-    }, this);
59  
-    text.onMouseOut = __bind(function() {
  59
+    };
  60
+    text.onMouseOut = function() {
60 61
       return text.fillStyle = 'rgba(0, 0, 0, 1)';
61  
-    }, this);
62  
-    stage.onMouseUp = __bind(function() {
  62
+    };
  63
+    stage.onMouseUp = function() {
63 64
       if (logo) {
64 65
         Tween.kill(logo);
65 66
         return Tween.to(logo, 500, {
@@ -67,15 +68,15 @@
67 68
           y: stage.mouseY
68 69
         });
69 70
       }
70  
-    }, this);
71  
-    moreShapes = new Sprite();
  71
+    };
  72
+    moreShapes = new CanvasLibrary.Sprite();
72 73
     moreShapes.x = 0;
73 74
     moreShapes.y = 0;
74  
-    moreShape1 = new Shape();
  75
+    moreShape1 = new CanvasLibrary.Shape();
75 76
     moreShape1.id = "moreShape1";
76 77
     moreShape1.fillStyle('rgba(0, 255, 0, 1)');
77 78
     moreShape1.fillRect(0, 0, 50, 50);
78  
-    moreShape2 = new Shape();
  79
+    moreShape2 = new CanvasLibrary.Shape();
79 80
     moreShape2.x = 10;
80 81
     moreShape2.y = 10;
81 82
     moreShape2.fillStyle('rgba(0, 255, 255, 1)');
@@ -101,7 +102,7 @@
101 102
         alpha: 1
102 103
       });
103 104
     });
104  
-    renderer = new Renderer(stage, 25);
  105
+    renderer = new CanvasLibrary.Renderer(stage, 25);
105 106
     renderer.run();
106 107
     Tween.to(someShape, 5000, {
107 108
       x: 100,
@@ -116,5 +117,7 @@
116 117
       scaleY: 1
117 118
     });
118 119
   };
  120
+
119 121
   window.onload = run;
  122
+
120 123
 }).call(this);
2  dev_demos_start
... ...
@@ -1,2 +0,0 @@
1  
-#!/bin/sh
2  
-coffee -w -c demos/*.coffee
2  dev_start
... ...
@@ -1,2 +0,0 @@
1  
-#!/bin/sh
2  
-coffee -w -b -o lib/ -c src/*.coffee
2  lib/ansii_palette.js
... ...
@@ -0,0 +1,2 @@
  1
+
  2
+
32  lib/bitmap.js
... ...
@@ -0,0 +1,32 @@
  1
+(function() {
  2
+  var Bitmap;
  3
+  var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
  4
+
  5
+  Bitmap = (function() {
  6
+
  7
+    __extends(Bitmap, DisplayObject);
  8
+
  9
+    function Bitmap(imageData) {
  10
+      this.imageData = imageData;
  11
+      Bitmap.__super__.constructor.call(this);
  12
+    }
  13
+
  14
+    Bitmap.prototype.draw = function(context, drawHitarea) {
  15
+      if (this.imageData) {
  16
+        if (this.drawHitarea) {
  17
+          return context.rect(0, 0, this.imageData.width, this.imageData.height);
  18
+        } else {
  19
+          return context.drawImage(this.imageData, 0, 0);
  20
+        }
  21
+      }
  22
+    };
  23
+
  24
+    return Bitmap;
  25
+
  26
+  })();
  27
+
  28
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  29
+
  30
+  this.CanvasLibrary.Bitmap = Bitmap;
  31
+
  32
+}).call(this);
22  lib/display_container.js
... ...
@@ -0,0 +1,22 @@
  1
+(function() {
  2
+  var DisplayContainer;
  3
+
  4
+  DisplayContainer = (function() {
  5
+
  6
+    function DisplayContainer() {}
  7
+
  8
+    DisplayContainer.prototype.draw = function(context, drawHitarea) {
  9
+      return true;
  10
+    };
  11
+
  12
+    return DisplayContainer;
  13
+
  14
+  })();
  15
+
  16
+  include(DisplayContainer, DisplayContainerMixin);
  17
+
  18
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  19
+
  20
+  this.CanvasLibrary.DisplayContainer = DisplayContainer;
  21
+
  22
+}).call(this);
53  lib/display_container_mixin.js
... ...
@@ -0,0 +1,53 @@
  1
+(function() {
  2
+  var DisplayContainerMixin;
  3
+
  4
+  DisplayContainerMixin = (function() {
  5
+
  6
+    function DisplayContainerMixin() {}
  7
+
  8
+    DisplayContainerMixin.addChild = function(child) {
  9
+      if (child.parent) child.parent.removeChild(child);
  10
+      if (this.stage) this.stage.childrenChanged = true;
  11
+      this.determineAncestors(child);
  12
+      child.stage = this.stage;
  13
+      child.translatedObjects = [child].concat(child.ancestors).reverse();
  14
+      this.children.push(child);
  15
+      return this;
  16
+    };
  17
+
  18
+    DisplayContainerMixin.removeChild = function(child) {
  19
+      var i;
  20
+      i = this.children.indexOf(child);
  21
+      if (i === -1) {
  22
+        throw 'Child object not found in DisplayList';
  23
+      } else {
  24
+        if (this.stage) this.stage.childrenChanged = true;
  25
+        this.children.splice(i, 1);
  26
+        child.parent = null;
  27
+        child.ancestors = null;
  28
+        child.translatedObjects = null;
  29
+        return this;
  30
+      }
  31
+    };
  32
+
  33
+    DisplayContainerMixin.determineAncestors = function(child) {
  34
+      var theParent;
  35
+      child.parent = this;
  36
+      child.ancestors = [];
  37
+      theParent = this;
  38
+      while (theParent) {
  39
+        child.ancestors.push(theParent);
  40
+        theParent = theParent.parent;
  41
+      }
  42
+      return true;
  43
+    };
  44
+
  45
+    return DisplayContainerMixin;
  46
+
  47
+  })();
  48
+
  49
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  50
+
  51
+  this.CanvasLibrary.DisplayContainerMixin = DisplayContainerMixin;
  52
+
  53
+}).call(this);
112  lib/display_object.js
... ...
@@ -0,0 +1,112 @@
  1
+(function() {
  2
+  var DisplayObject;
  3
+
  4
+  DisplayObject = (function() {
  5
+
  6
+    function DisplayObject() {
  7
+      this.id = '';
  8
+      this.x = 0;
  9
+      this.y = 0;
  10
+      this.oldX = null;
  11
+      this.oldY = null;
  12
+      this.calculatedX = 0;
  13
+      this.calculatedY = 0;
  14
+      this.width = 0;
  15
+      this.height = 0;
  16
+      this.alpha = 1;
  17
+      this.oldAlpha = 1;
  18
+      this.calculatedAlpha = 1;
  19
+      this.scaleX = 1;
  20
+      this.scaleY = 1;
  21
+      this.oldScaleX = null;
  22
+      this.oldScaleY = null;
  23
+      this.calculatedScaleX = 1;
  24
+      this.calculatedScaleY = 1;
  25
+      this.rotation = 0;
  26
+      this.oldRotation = null;
  27
+      this.calculatedRotation = 0;
  28
+      this.enabled = true;
  29
+      this.visible = true;
  30
+      this.oldVisible = null;
  31
+      this.calculatedVisibility = true;
  32
+      this.mouseEnabled = false;
  33
+      this.mouseDown = false;
  34
+      this.useHandCursor = false;
  35
+      this.shadow = false;
  36
+      this.shadowBlur = 0;
  37
+      this.shadowColor = 0;
  38
+      this.shadowOffsetX = 0;
  39
+      this.shadowOffsetY = 0;
  40
+      this.onMouseOver = null;
  41
+      this.onMouseOut = null;
  42
+      this.onMouseDown = null;
  43
+      this.onMouseMove = null;
  44
+      this.localX = 0;
  45
+      this.localY = 0;
  46
+      this.isMouseSetup = false;
  47
+      this.mouseDown = false;
  48
+      this.lastObjectUnderCursor = null;
  49
+      this.stage = null;
  50
+      this.parent = null;
  51
+      this.ancestors = null;
  52
+      this.translatedObjects = null;
  53
+      this.childrenChanged = false;
  54
+    }
  55
+
  56
+    DisplayObject.prototype.draw = function(context, drawHitarea) {};
  57
+
  58
+    DisplayObject.prototype.calculateCanvasPositions = function() {
  59
+      var newVars;
  60
+      if (this.positionChanged()) {
  61
+        this.oldX = this.x;
  62
+        this.oldY = this.y;
  63
+        this.oldVisible = this.visible;
  64
+        this.oldAlpha = this.alpha;
  65
+        newVars = this.getInheritedTranslatedVars();
  66
+        this.calculatedX = newVars[0];
  67
+        this.calculatedY = newVars[1];
  68
+        this.calculatedVisibility = newVars[2];
  69
+        return this.calculatedAlpha = newVars[3];
  70
+      }
  71
+    };
  72
+
  73
+    DisplayObject.prototype.getInheritedTranslatedVars = function() {
  74
+      var theParent, translatedAlpha, translatedVisibility, translatedX, translatedY;
  75
+      theParent = this;
  76
+      translatedX = 0;
  77
+      translatedY = 0;
  78
+      translatedVisibility = true;
  79
+      translatedAlpha = 1;
  80
+      while (theParent) {
  81
+        translatedX += theParent.x;
  82
+        translatedY += theParent.y;
  83
+        if (!theParent.visible) translatedVisibility = false;
  84
+        translatedAlpha *= theParent.alpha;
  85
+        theParent = theParent.parent;
  86
+      }
  87
+      return [translatedX, translatedY, translatedVisibility, translatedAlpha];
  88
+    };
  89
+
  90
+    DisplayObject.prototype.positionChanged = function() {
  91
+      return this.x !== this.oldX || this.y !== this.oldY || this.rotation !== this.oldRotation || this.scaleX !== this.oldScaleX || this.scaleY !== this.oldScaleY || this.visible !== this.old || this.ancestorsPositionChanged();
  92
+    };
  93
+
  94
+    DisplayObject.prototype.ancestorsPositionChanged = function() {
  95
+      var ancestor, _i, _len, _ref;
  96
+      _ref = this.ancestors;
  97
+      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  98
+        ancestor = _ref[_i];
  99
+        if (ancestor.positionChanged()) return true;
  100
+      }
  101
+      return false;
  102
+    };
  103
+
  104
+    return DisplayObject;
  105
+
  106
+  })();
  107
+
  108
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  109
+
  110
+  this.CanvasLibrary.DisplayObject = DisplayObject;
  111
+
  112
+}).call(this);
12  lib/ease_default.js
... ...
@@ -0,0 +1,12 @@
  1
+(function() {
  2
+  var EaseDefault;
  3
+
  4
+  EaseDefault = function(t, b, c, d) {
  5
+    return -c * (t /= d) * (t - 2) + b;
  6
+  };
  7
+
  8
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  9
+
  10
+  this.CanvasLibrary.EaseDefault = EaseDefault;
  11
+
  12
+}).call(this);
81  lib/pixel_sprite.js
... ...
@@ -0,0 +1,81 @@
  1
+(function() {
  2
+  var PixelSprite;
  3
+  var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
  4
+
  5
+  PixelSprite = (function() {
  6
+
  7
+    __extends(PixelSprite, Shape);
  8
+
  9
+    PixelSprite.defaultColorPalette = ['rgba(0, 0, 0, 1)', 'rgba(170, 0, 0, 1)', 'rgba(0, 170, 0, 1)', 'rgba(170, 85, 0, 1)', 'rgba(0, 0, 170, 1)', 'rgba(170, 0, 170, 1)', 'rgba(0, 170, 170, 1)', 'rgba(170, 170, 170, 1)', 'rgba(85, 85, 85, 1)', 'rgba(255, 85, 85, 1)', 'rgba(82, 255, 85, 1)', 'rgba(255, 255, 85, 1)', 'rgba(85, 85, 255, 1)', 'rgba(255, 85, 255, 1)', 'rgba(85, 255, 255, 1)', 'rgba(255, 255, 255, 1)'];
  10
+
  11
+    function PixelSprite(map) {
  12
+      PixelSprite.__super__.constructor.call(this);
  13
+      this.pixels = [];
  14
+      this.colorPalette = PixelSprite.defaultColorPalette;
  15
+      this.pixelSize = 4;
  16
+      if (map) this.drawPixelMap(map);
  17
+    }
  18
+
  19
+    PixelSprite.prototype.drawPixelMap = function(map) {
  20
+      var color, column, columns, row, rows, x, y, _i, _j, _len, _len2;
  21
+      x = 0;
  22
+      y = 0;
  23
+      rows = map.split("\n");
  24
+      for (_i = 0, _len = rows.length; _i < _len; _i++) {
  25
+        row = rows[_i];
  26
+        columns = row.split('');
  27
+        x = 0;
  28
+        for (_j = 0, _len2 = columns.length; _j < _len2; _j++) {
  29
+          column = columns[_j];
  30
+          color = column.charCodeAt(0);
  31
+          if (this.colorPalette[color]) {
  32
+            this.drawPixel(x, y, this.colorPalette[color]);
  33
+          }
  34
+          x++;
  35
+        }
  36
+        y++;
  37
+      }
  38
+      return this.submitPixels();
  39
+    };
  40
+
  41
+    PixelSprite.prototype.drawPixel = function(x, y, color) {
  42
+      if (!this.pixels[y]) this.pixels[y] = [];
  43
+      return this.pixels[y][x] = color;
  44
+    };
  45
+
  46
+    PixelSprite.prototype.removePixel = function(x, y) {
  47
+      return this.pixels[y][x] = null;
  48
+    };
  49
+
  50
+    PixelSprite.prototype.submitPixels = function() {
  51
+      var column, row, x, y, _i, _j, _len, _len2, _ref, _results;
  52
+      x = 0;
  53
+      y = 0;
  54
+      _ref = this.pixels;
  55
+      _results = [];
  56
+      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  57
+        row = _ref[_i];
  58
+        x = 0;
  59
+        if (row) {
  60
+          for (_j = 0, _len2 = row.length; _j < _len2; _j++) {
  61
+            column = row[_j];
  62
+            if (column) {
  63
+              this.fillRect(x * this.pixelSize, y * this.pixelSize, this.pixelSize, this.pixelSize, column);
  64
+            }
  65
+            x++;
  66
+          }
  67
+        }
  68
+        _results.push(y++);
  69
+      }
  70
+      return _results;
  71
+    };
  72
+
  73
+    return PixelSprite;
  74
+
  75
+  })();
  76
+
  77
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  78
+
  79
+  this.CanvasLibrary.PixelSprite = PixelSprite;
  80
+
  81
+}).call(this);
60  lib/renderer.js
... ...
@@ -0,0 +1,60 @@
  1
+(function() {
  2
+  var Renderer;
  3
+
  4
+  Renderer = (function() {
  5
+
  6
+    function Renderer(stage, fps) {
  7
+      this.timer = null;
  8
+      this.running = false;
  9
+      this.frameHandlers = null;
  10
+      this.stage = stage;
  11
+      this.setFps(fps);
  12
+    }
  13
+
  14
+    Renderer.prototype.setFps = function(fps) {
  15
+      return this.interval = 1000 / fps;
  16
+    };
  17
+
  18
+    Renderer.prototype.run = function(fps) {
  19
+      if (fps) this.setFps(fps);
  20
+      if (this.running) this.stop();
  21
+      this.running = true;
  22
+      return this.timer = setInterval(this.handleInterval, this.interval, this);
  23
+    };
  24
+
  25
+    Renderer.prototype.addFrameHandler = function(handler) {
  26
+      this.frameHandlers || (this.frameHandlers = []);
  27
+      if (this.frameHandlers.indexOf(handler) === -1) {
  28
+        this.frameHandlers.push(handler);
  29
+      }
  30
+      return this;
  31
+    };
  32
+
  33
+    Renderer.prototype.handleInterval = function(self) {
  34
+      var frameHandler, _i, _len, _ref;
  35
+      if (self.frameHandlers) {
  36
+        _ref = self.frameHandlers;
  37
+        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  38
+          frameHandler = _ref[_i];
  39
+          frameHandler();
  40
+        }
  41
+      }
  42
+      Tween.update();
  43
+      return self.stage.render(true);
  44
+    };
  45
+
  46
+    Renderer.prototype.stop = function() {
  47
+      clearInterval(this.timer);
  48
+      this.running = false;
  49
+      return this.timer = null;
  50
+    };
  51
+
  52
+    return Renderer;
  53
+
  54
+  })();
  55
+
  56
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  57
+
  58
+  this.CanvasLibrary.Renderer = Renderer;
  59
+
  60
+}).call(this);
182  lib/shape.js
... ...
@@ -0,0 +1,182 @@
  1
+(function() {
  2
+  var Shape;
  3
+  var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
  4
+
  5
+  Shape = (function() {
  6
+
  7
+    __extends(Shape, DisplayObject);
  8
+
  9
+    function Shape() {
  10
+      Shape.__super__.constructor.call(this);
  11
+      this.madeChanges = false;
  12
+      this.drawingCommands = [];
  13
+    }
  14
+
  15
+    Shape.prototype.clear = function() {
  16
+      this.madeChanges = true;
  17
+      this.drawingCommands = [];
  18
+      return true;
  19
+    };
  20
+
  21
+    Shape.prototype.addColorStops = function(gradient, colorStops) {
  22
+      var colorStop, _i, _len;
  23
+      for (_i = 0, _len = colorStops.length; _i < _len; _i++) {
  24
+        colorStop = colorStops[_i];
  25
+        gradient.addColorStop(colorStop[0], colorStop[1]);
  26
+      }
  27
+      return gradient;
  28
+    };
  29
+
  30
+    Shape.prototype.createRadialGradient = function(x1, y1, r1, x2, y2, r2, colorStops) {
  31
+      var gradient;
  32
+      gradient = this.stage.backBufferContext.createRadialGradient(x1, y1, r1, x2, y2, r2);
  33
+      this.addColorStops(gradient, colorStops);
  34
+      return gradient;
  35
+    };
  36
+
  37
+    Shape.prototype.createLinearGradient = function(x1, y1, x2, y2, colorStops) {
  38
+      var gradient;
  39
+      gradient = this.stage.backBufferContext.createLinearGradient(x1, y1, x2, y2);
  40
+      this.addColorStops(gradient, colorStops);
  41
+      return gradient;
  42
+    };
  43
+
  44
+    Shape.prototype.setRadialGradient = function(x1, y1, r1, x2, y2, r2, colorStops) {
  45
+      this.fillStyle(this.createRadialGradient(x1, y1, r1, x2, y2, r2, colorStops));
  46
+      return this;
  47
+    };
  48
+
  49
+    Shape.prototype.setLinearGradient = function(x1, y1, x2, y2, colorStops) {
  50
+      this.fillStyle(this.createLinearGradient(x1, y1, x2, y2, colorStops));
  51
+      return this;
  52
+    };
  53
+
  54
+    Shape.prototype.moveTo = function(x, y) {
  55
+      this.drawingCommands.push([true, 'moveTo', x, y]);
  56
+      return this;
  57
+    };
  58
+
  59
+    Shape.prototype.lineWidth = function(thickness) {
  60
+      this.drawingCommands.push([true, 'lineWidth', thickness]);
  61
+      return this;
  62
+    };
  63
+
  64
+    Shape.prototype.lineCap = function(cap) {
  65
+      this.drawingCommands.push([true, 'lineCap', cap]);
  66
+      return true;
  67
+    };
  68
+
  69
+    Shape.prototype.lineTo = function(x, y) {
  70
+      this.madeChanges = true;
  71
+      this.drawingCommands.push([true, 'lineTo', x, y]);
  72
+      return this;
  73
+    };
  74
+
  75
+    Shape.prototype.bezierCurveTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {
  76
+      this.madeChanges = true;
  77
+      this.drawingCommands.push([true, 'bezierCurveTo', cp1x, cp1y, cp2x, cp2y, x, y]);
  78
+      return this;
  79
+    };
  80
+
  81
+    Shape.prototype.quadraticCurveTo = function(cpx, cpy, x, y) {
  82
+      this.madeChanges = true;
  83
+      this.drawingCommands.push([true, 'quadraticCurveTo', cpx, cpy, x, y]);
  84
+      return this;
  85
+    };
  86
+
  87
+    Shape.prototype.miterLimit = function(ratio) {
  88
+      this.drawingCommands.push([true, 'miterLimit', ratio]);
  89
+      return this;
  90
+    };
  91
+
  92
+    Shape.prototype.beginPath = function() {
  93
+      this.drawingCommands.push([false, 'beginPath']);
  94
+      return this;
  95
+    };
  96
+
  97
+    Shape.prototype.closePath = function() {
  98
+      this.drawingCommands.push([false, 'closePath']);
  99
+      return this;
  100
+    };
  101
+
  102
+    Shape.prototype.fillRect = function(x, y, width, height, color) {
  103
+      this.madeChanges = true;
  104
+      if (color) this.fillStyle(color);
  105
+      this.drawingCommands.push([true, 'rect', x, y, width, height]);
  106
+      this.drawingCommands.push([false, 'fillRect', x, y, width, height]);
  107
+      return this;
  108
+    };
  109
+
  110
+    Shape.prototype.circle = function(x, y, radius) {
  111
+      this.arc(x, y, radius / 2, 0, Math.PI * 2, true);
  112
+      return this;
  113
+    };
  114
+
  115
+    Shape.prototype.arc = function(x, y, r, sr, er, cw) {
  116
+      this.madeChanges = true;
  117
+      this.drawingCommands.push([true, 'arc', x, y, r, sr, er, cw]);
  118
+      return this;
  119
+    };
  120
+
  121
+    Shape.prototype.strokeRect = function(x, y, width, height, color) {
  122
+      this.madeChanges = true;
  123
+      this.drawingCommands.push([true, 'rect', x, y, width, height]);
  124
+      this.drawingCommands.push([false, 'strokeRect', x, y, width, height]);
  125
+      return this;
  126
+    };
  127
+
  128
+    Shape.prototype.clearRect = function(x, y, width, height) {
  129
+      this.madeChanges = true;
  130
+      return this.drawingCommands.push([true, 'clearRect', x, y, width, height]);
  131
+    };
  132
+
  133
+    Shape.prototype.fillStyle = function(color) {
  134
+      this.drawingCommands.push([false, 'fillStyle=', color]);
  135
+      return this;
  136
+    };
  137
+
  138
+    Shape.prototype.strokeStyle = function(color) {
  139
+      this.drawingCommands.push([false, 'strokeStyle=', color]);
  140
+      return this;
  141
+    };
  142
+
  143
+    Shape.prototype.globalAlpha = function(alpha) {
  144
+      this.madeChanges = true;
  145
+      this.drawingCommands.push([false, 'globalAlpha=', alpha]);
  146
+      return this;
  147
+    };
  148
+
  149
+    Shape.prototype.fill = function() {
  150
+      this.madeChanges = true;
  151
+      this.drawingCommands.push([false, 'fill']);
  152
+      return this;
  153
+    };
  154
+
  155
+    Shape.prototype.draw = function(context, drawHitarea) {
  156
+      var command, instruction, _i, _len, _ref;
  157
+      _ref = this.drawingCommands;
  158
+      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  159
+        command = _ref[_i];
  160
+        instruction = command[1];
  161
+        if (!drawHitarea || (drawHitarea && command[0])) {
  162
+          if (instruction.substr(-1, 1) === '=' && command.length === 3) {
  163
+            context[instruction.substr(0, instruction.length - 1)] = command[2];
  164
+          } else if (command.length > 2) {
  165
+            context[instruction].apply(context, command.slice(2));
  166
+          } else if (command.length === 2) {
  167
+            context[instruction]();
  168
+          }
  169
+        }
  170
+      }
  171
+      return this.madeChanges = false;
  172
+    };
  173
+
  174
+    return Shape;
  175
+
  176
+  })();
  177
+
  178
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  179
+
  180
+  this.CanvasLibrary.Shape = Shape;
  181
+
  182
+}).call(this);
24  lib/sprite.js
... ...
@@ -0,0 +1,24 @@
  1
+(function() {
  2
+  var Sprite;
  3
+  var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
  4
+
  5
+  Sprite = (function() {
  6
+
  7
+    __extends(Sprite, Shape);
  8
+
  9
+    function Sprite() {
  10
+      Sprite.__super__.constructor.call(this);
  11
+      this.children = [];
  12
+    }
  13
+
  14
+    return Sprite;
  15
+
  16
+  })();
  17
+
  18
+  include(Sprite, DisplayContainerMixin);
  19
+
  20
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  21
+
  22
+  this.CanvasLibrary.Sprite = Sprite;
  23
+
  24
+}).call(this);
124  lib/stacked_loader.js
... ...
@@ -0,0 +1,124 @@
  1
+(function() {
  2
+  var StackedLoader;
  3
+
  4
+  StackedLoader = (function() {
  5
+
  6
+    function StackedLoader() {}
  7
+
  8
+    StackedLoader.stack = {};
  9
+
  10
+    StackedLoader.loadStack = [];
  11
+
  12
+    StackedLoader.toLoad = null;
  13
+
  14
+    StackedLoader.onCompleteHandlers = [];
  15
+
  16
+    StackedLoader.loading = false;
  17
+
  18
+    StackedLoader.add = function(id, type, url) {
  19
+      if (this.stack[id]) this.remove(id);
  20
+      return this.loadStack.push({
  21
+        type: type,
  22
+        url: url,
  23
+        id: id
  24
+      });
  25
+    };
  26
+
  27
+    StackedLoader.load = function(onCompleteHandler) {
  28
+      if (onCompleteHandler != null) {
  29
+        this.onCompleteHandlers.push(onCompleteHandler);
  30
+      }
  31
+      if (!this.loading) {
  32
+        this.loading = true;
  33
+        return this.loadNext();
  34
+      }
  35
+    };
  36
+
  37
+    StackedLoader.get = function(id) {
  38
+      return this.stack[id];
  39
+    };
  40
+
  41
+    StackedLoader.getClonedBitmap = function(id) {
  42
+      return new Bitmap(this.stack[this.toLoad.id]);
  43
+    };
  44
+
  45
+    StackedLoader.loadNext = function() {
  46
+      var onCompleteHandler, _i, _len, _ref;
  47
+      if (this.loadStack.length === 0) {
  48
+        _ref = this.onCompleteHandlers;
  49
+        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  50
+          onCompleteHandler = _ref[_i];
  51
+          onCompleteHandler();
  52
+        }
  53
+        this.onCompleteHandlers = [];
  54
+        return this.loading = false;
  55
+      } else {
  56
+        this.toLoad = this.loadStack[0];
  57
+        return this['load' + Utils.firstUpcase(this.toLoad.type)]();
  58
+      }
  59
+    };
  60
+
  61
+    StackedLoader.loadString = function() {
  62
+      var _this = this;
  63
+      this.stack[this.toLoad.id] = new XMLHttpRequest();
  64
+      this.stack[this.toLoad.id].onreadystatechange = function() {
  65
+        if (_this.stack[_this.toLoad.id].readyState === 4 && _this.stack[_this.toLoad.id].status === 200) {
  66
+          return _this['handle' + Utils.firstUpcase(_this.toLoad.type) + 'LoadComplete']();
  67
+        }
  68
+      };
  69
+      this.stack[this.toLoad.id].open('GET', this.toLoad.url, true);
  70
+      return this.stack[this.toLoad.id].send(null);
  71
+    };
  72
+
  73
+    StackedLoader.loadBitmap = function() {
  74
+      var _this = this;
  75
+      this.stack[this.toLoad.id] = new Image();
  76
+      this.stack[this.toLoad.id].onload = function() {
  77
+        return _this.handleBitmapLoadComplete();
  78
+      };
  79
+      return this.stack[this.toLoad.id].src = this.toLoad.url;
  80
+    };
  81
+
  82
+    StackedLoader.loadSprite = function() {
  83
+      return this.loadString();
  84
+    };
  85
+
  86
+    StackedLoader.loadAudio = function() {
  87
+      this.stack[this.toLoad.id] = new Audio();
  88
+      this.stack[this.toLoad.id].src = this.toLoad.url;
  89
+      return this.handleAssetLoadComplete();
  90
+    };
  91
+
  92
+    StackedLoader.handleBitmapLoadComplete = function() {
  93
+      this.stack[this.toLoad.id].onload = null;
  94
+      this.stack[this.toLoad.id] = new Bitmap(this.stack[this.toLoad.id]);
  95
+      this.stack[this.toLoad.id].id = this.toLoad.id;
  96
+      return this.handleAssetLoadComplete();
  97
+    };
  98
+
  99
+    StackedLoader.handleStringLoadComplete = function() {
  100
+      this.stack[this.toLoad.id].onreadystatechange = null;
  101
+      this.stack[this.toLoad.id] = this.stack[this.toLoad.id].responseText;
  102
+      return this.handleAssetLoadComplete;
  103
+    };
  104
+
  105
+    StackedLoader.handleSpriteLoadComplete = function() {
  106
+      this.stack[this.toLoad.id].onreadystatechange = null;
  107
+      this.stack[this.toLoad.id] = new PixelSprite(this.stack[this.toLoad.id].responseText);
  108
+      return this.handleAssetLoadComplete;
  109
+    };
  110
+
  111
+    StackedLoader.handleAssetLoadComplete = function() {
  112
+      this.loadStack.splice(0, 1);
  113
+      return this.loadNext();
  114
+    };
  115
+
  116
+    return StackedLoader;
  117
+
  118
+  })();
  119
+
  120
+  this.CanvasLibrary || (this.CanvasLibrary = {});
  121
+
  122
+  this.CanvasLibrary.StackedLoader = StackedLoader;
  123
+
  124
+}).call(this);
225  lib/stage.js
... ...
@@ -0,0 +1,225 @@
  1
+(function() {
  2
+  var Stage;
  3
+
  4
+  Stage = (function() {
  5
+
  6
+    function Stage(canvasId) {
  7
+      var _this = this;
  8
+      this.canvasId = canvasId;
  9
+      this.stage = this;
  10
+      this.children = [];
  11
+      this.scaleX = 1;
  12
+      this.scaleY = 1;
  13
+      this.rotation = 0;
  14
+      this.visible = true;
  15
+      this.x = 0;
  16
+      this.y = 0;
  17
+      this.alpha = 1;
  18
+      this.mouseX = 0;
  19
+      this.mouseY = 0;
  20
+      this.parent = null;
  21
+      this.isMouseSetup = false;
  22
+      this.oldMouseX = 0;
  23
+      this.oldMouseY = 0;
  24
+      this.children = [];
  25
+      this.canvas = document.getElementById(this.canvasId);
  26
+      this.context = this.canvas.getContext('2d');
  27
+      this.hitBufferCanvas = this.cloneCanvas();
  28
+      this.hitBufferContext = this.hitBufferCanvas.getContext('2d');
  29
+      this.childrenChanged = false;
  30
+      this.allChildren = [];
  31
+      this.canvasOffsetPosition = Utils.offsetPosition(this.canvas);
  32
+      window.onresize = function() {
  33
+        return _this.handleWindowResize();
  34
+      };
  35
+    }
  36
+
  37
+    Stage.prototype.cloneCanvas = function() {
  38
+      var canvas;
  39
+      canvas = document.createElement('canvas');
  40
+      canvas.width = this.canvas.width;
  41
+      canvas.height = this.canvas.height;
  42
+      return canvas;
  43
+    };
  44
+
  45
+    Stage.prototype.render = function(clear) {
  46
+      this.setupMouse();
  47
+      this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
  48
+      if (this.childrenChanged) {
  49
+        this.findAllChildren();
  50
+        this.childrenChanged = false;
  51
+      }
  52
+      this.drawAllChildren();
  53
+      return this.handleMouseEventsOfAllChildren();
  54
+    };
  55
+
  56
+    Stage.prototype.setupContext = function(context, child) {
  57
+      var object, _i, _len, _ref;
  58
+      context.globalAlpha = child.calculatedAlpha;
  59
+      _ref = child.translatedObjects;
  60
+      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  61
+        object = _ref[_i];
  62
+        context.translate(object.x, object.y);
  63
+        context.rotate(Utils.angleToRadians(object.rotation));
  64
+        context.scale(object.scaleX, object.scaleY);
  65
+      }
  66
+      if (child.shadow) {
  67
+        context.shadowBlur = child.shadowBlur;
  68
+        context.shadowColor = child.shadowColor;
  69
+        context.shadowOffsetX = child.shadowOffsetX;
  70
+        return context.shadowOffsetY = child.shadowOffsetY;
  71
+      }
  72
+    };
  73
+
  74
+    Stage.prototype.drawAllChildren = function() {
  75
+      var child, _i, _len, _ref, _results;
  76
+      _ref = this.allChildren;
  77
+      _results = [];
  78
+      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  79
+        child = _ref[_i];