浏览代码

Merge branch 'development' of github.com:snaky-particles/snaky-particles into models

Dima Mironov 10 年之前
父节点
当前提交
b930211ea5
共有 3 个文件被更改,包括 31 次插入1 次删除
  1. 5 1
      js/controller.js
  2. 10 0
      js/script.js
  3. 16 0
      js/views/particle.js

+ 5 - 1
js/controller.js

@@ -43,7 +43,8 @@ Controller.prototype.start_game = function(){
 	// this.session = new Session();
     var c = this;
 	createjs.Ticker.on("tick", function(e){c.tick(e);});
-	createjs.Ticker.setFPS(20);
+    createjs.Ticker.addEventListener("tick", this.stage);
+    createjs.Ticker.timingMode = createjs.Ticker.RAF;
 	this.bind_events();
 	this.time = 0;
 
@@ -57,6 +58,9 @@ Controller.prototype.start_game = function(){
 Controller.prototype.add_view = function(view){
     this.stage.addChild(view);
     this.views.push(view);
+    if(view.animate){
+        view.animate();
+    }
 }
 
 Controller.prototype.bind_events = function(){

+ 10 - 0
js/script.js

@@ -6,6 +6,16 @@ function init() {
     resize();
 
     controller.start_game();
+
+    var p2 = new Particle({x: 10, y: 10});
+    p2.start_time = createjs.Ticker.getTime();
+    p2.target = {
+        time: p2.start_time + 1000,
+        x: 12,
+        y: 15
+    }
+    var p2v = new ParticleView(p2);
+    controller.add_view(p2v);
 }
 
 function resize() {

+ 16 - 0
js/views/particle.js

@@ -17,5 +17,21 @@
         this.y = cell_size * this.model.position.y;
     }
 
+    ParticleView.prototype.animate = function(){
+        if(this.model.target){
+            var own_view = this;
+            this.update();
+            this.update = function(){};
+            createjs.Tween.get(this).to(
+                { x: cell_size * this.model.target.x, y: cell_size * this.model.target.y },
+                this.model.target.time - this.model.start_time
+            ).call(function(){
+                own_view.update = ParticleView.prototype.update;
+                own_view.model.position.x = own_view.model.target.x;
+                own_view.model.position.y = own_view.model.target.y;
+            });
+        }
+    }
+
     window.ParticleView = ParticleView;
 }(window));