Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. update: function() {
  2. // Update all entities and backgroundMaps
  3. if( ig.input.pressed('select')) {
  4. // Do this once
  5. if(this.selectBox !== null){
  6. var i,creatures;
  7. creatures = this.getEntitiesByType("EntityCreature");
  8. // clear all other selections
  9. for(i=0;i<creatures.length;i++){
  10. if(creatures[i].selected){
  11. creatures[i].deselect();
  12. }
  13. }
  14. }
  15. console.log("Startpos");
  16. this.selectBox = {};
  17. this.selectBox.startx = this.selectBox.x = ig.input.mouse.x;
  18. this.selectBox.starty = this.selectBox.y = ig.input.mouse.y;
  19. console.log("Started:",this.selectBox);
  20. }else if(!!ig.input.state('select') && this.selectBox !== null){
  21. if(!(this.selectBox.x === ig.input.mouse.x && this.selectBox.y === ig.input.mouse.y)){
  22. console.log("drawing select?, setting selectBox");
  23. this.selectBox.x = ig.input.mouse.x;
  24. this.selectBox.y = ig.input.mouse.y;
  25. }
  26. }else{
  27. if (!ig.input.state('select') &&
  28. this.selectBox !== null &&
  29. !(this.selectBox.x === this.selectBox.startx && this.selectBox.y === this.selectBox.starty)
  30. ){ // false
  31. this.selectBox.x = ig.input.mouse.x;
  32. this.selectBox.y = ig.input.mouse.y;
  33. ig.system.context.strokeStyle = '#f00'; // red
  34. ig.system.context.lineWidth = 1;
  35. ig.system.context.strokeRect (
  36. this.selectBox.startx
  37. this.selectBox.starty
  38. this.selectBox.x
  39. this.selectBox.y
  40. );
  41. console.log("ended:",this.selectBox);
  42. throw Exception("tesT");
  43. }
  44. //console.log("set selectBox null in final");
  45. this.selectBox = null;
  46. }
  47. this.parent();
  48.  
  49. // Add your own, additional update code here
  50. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement