Browse Source

implement viewobject for physicist

just testing
Kevin Heinicke 10 years ago
parent
commit
d797e93a5d
3 changed files with 60 additions and 0 deletions
  1. 11 0
      css/style.css
  2. 34 0
      js/script.js
  3. 15 0
      js/views/physicist.js

+ 11 - 0
css/style.css

@@ -0,0 +1,11 @@
+body {
+    background: #144503;
+    padding: 0px;
+    margin: 0px;
+}
+
+#demoCanvas {
+    margin: 0px auto;
+    padding: 0px auto;
+    background: #fff;
+}

+ 34 - 0
js/script.js

@@ -0,0 +1,34 @@
+var stage;
+
+function init() {
+    stage = new createjs.Stage("demoCanvas");
+
+    var dummyModel = {position: {x: 10, y: 20}};
+    var p = new PhysicistView(dummyModel);
+    stage.addChild(p);
+
+    createjs.Ticker.on("tick", tick);
+    createjs.Ticker.setFPS(60);
+
+    var time = 0;
+    
+    function tick(event) {
+        time = event.time - time > 400 ? event.time : time;
+    
+        // time based
+        if(event.time == time){
+            dummyModel.position.x += 20;        
+            p.update();
+            stage.update(event);
+        }
+    }
+
+    resize();
+}
+
+function resize() {
+    stage.canvas.width = window.innerWidth;
+    stage.canvas.height = window.innerHeight;
+}
+
+function 

+ 15 - 0
js/views/physicist.js

@@ -0,0 +1,15 @@
+(function(window) {
+    function PhysicistView(modelObject){
+        this.graphics.beginFill("red").drawCircle(0, 0, 20);
+        this.model = modelObject;
+    }
+
+    PhysicistView.prototype = new createjs.Shape();
+
+    PhysicistView.prototype.update = function(){
+        this.x = this.model.position.x;
+        this.y = this.model.position.y;
+    }
+
+    window.PhysicistView = PhysicistView;
+}(window));