Advertisement
amigojapan

collision detection in phaser

Feb 15th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (these values were different)
  2. game_objectA.sprite.getBounds().x
  3. 285
  4. game_objectA.sprite.x
  5. 180
  6.  
  7. solution I did, but it may be slow I hacked together was making my own rectangle collision detection functions, here it is:
  8. function intersectRect(s1, s2) {
  9.     var r1={};
  10.     var r2={};
  11.     r1.top =  s1.y;
  12.     r1.left = s1.x;
  13.     r1.right = s1.x+s1.width;
  14.     r1.bottom = s1.y+s1.height;
  15.     r2.top =  s2.y;
  16.     r2.left = s2.x;
  17.     r2.right = s2.x+s2.width;
  18.     r2.bottom = s2.y+s2.height;    
  19.     return !(   r2.left > r1.right ||
  20.                 r2.right < r1.left ||
  21.                 r2.top > r1.bottom ||
  22.                 r2.bottom < r1.top);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement