Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.      * checks if mouse hits an objectentity and dispatches given events
  3.      * @param {CustomEvent} mouseEvent - event containing mouse position
  4.      * @param {CustomEvent} event1 ButtonClickEvent or ButtonFocusEvent
  5.      * @param {CustomEvent} event2 undefined or ButtonUnfocusEvent
  6.      */
  7.     this.getObjectEntityOnEvent = function(mouseEvent, event1, event2) {
  8.          
  9.         // checking - if Scene is active
  10.         if(that.active) {
  11.            
  12.             // get position
  13.             that.rect = that.domEl.getBoundingClientRect();
  14.    
  15.             // calculate mouse coordinates
  16.             jumruCore.mouseBox.setBox((mouseEvent.clientX -that.rect.left),(mouseEvent.clientY -that.rect.top),1,1);
  17.  
  18.             // get layers
  19.             var length = that.children.length;
  20.            
  21.             // get highest layer first
  22.             for(var i = length-1; i >= 0; i--) {
  23.                            
  24.                 // get ObjectEntities
  25.                 var oeLength = that.children[i].children.length;
  26.            
  27.                 // get highest ObjectEntity first
  28.                 for(var j = oeLength-1; j >= 0; j--) {
  29.    
  30.                     var oe = that.children[i].children[j]; 
  31.                    
  32.                     if(oe.active) {
  33.                         // if ObjectEntity is active, check if it is clicked
  34.                         if(oe instanceof jumru.ObjectEntity) {
  35.                            
  36.                             if(oe.isTouched()){        
  37.                                
  38.                                 //if an element in the menu map is defined
  39.                                 //update it as current button
  40.                                 if(jumruCore.inputmanager.menuMap[jumruCore.gamemode]){
  41.                                     jumruCore.inputmanager.menuMap[jumruCore.gamemode].setCurrButton(oe);
  42.                                 }
  43.                                
  44.                                 oe.fire(event1); //ButtonClick, ButtonFocus
  45.                                 return;
  46.                             }
  47.                             /*//TODO not used any longer?
  48.                             else {
  49.                                 if(event2 != undefined) {
  50.                                     console.log(oe.name);
  51.                                     oe.fire(event2); //ButtonUnfocus
  52.                                 }
  53.                             }*/
  54.                         }
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.     };
  60.        
  61.     //add scene to jumruCore.scenes
  62.     jumruCore.scenes.push(this);
  63.    
  64.     return this;
  65. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement