physicist.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. (function(window) {
  2. function PhysicistView(modelObject){
  3. // this.graphics.beginFill("red").drawCircle(0, 0, window.cell_size * 0.9 / 2);
  4. var width = 131;
  5. var height = 135;
  6. var spriteSheet = new createjs.SpriteSheet({
  7. framerate: 15,
  8. images: ["img/physicist/physicist-spritesheet.png"],
  9. frames: {regX: height/2, height: height, count: 8, regY: width/2, width: width},
  10. animations: {
  11. run: [0, 7]
  12. }
  13. });
  14. var scale = width > height ? cell_size / width : cell_size / height;
  15. this.scaleX = scale;
  16. this.scaleY = scale;
  17. this.spriteSheet = spriteSheet;
  18. this.gotoAndPlay("run");
  19. this.model = modelObject;
  20. }
  21. PhysicistView.prototype = new createjs.Sprite();
  22. // PhysicistView.prototype = new createjs.Shape();
  23. PhysicistView.prototype.update = function(){
  24. this.x = cell_size * this.model.position.x;
  25. this.y = cell_size * this.model.position.y;
  26. this.rotation = this.model.direction.x > 0 ? -90 :
  27. this.model.direction.x < 0 ? 90 :
  28. this.model.direction.y > 0 ? 0 : 180;
  29. }
  30. window.PhysicistView = PhysicistView;
  31. }(window));