Advertisement
Guest User

Rotation Check Bound

a guest
Jan 6th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //########## for stage boundary
  2. private var rotAngle:int; // THIS IS YOUR ROTATION ANGLE, DEFINE AT THE START BEFORE SETUP.
  3. private var axisArray:Array = [];
  4. private var trueX:int = -465;
  5. private var trueY:int = -17;
  6. private var northBound:int;
  7. private var southBound:int;
  8. private var eastBound:int;
  9. private var westBound:int;
  10.  
  11.  
  12. //########## during setup
  13. if (trueY < 0) {
  14.     northBound = Math.abs(trueY);
  15.     southBound = this.height - Math.abs(trueY);
  16. } else {
  17.     northBound = 0;
  18.     southBound = this.height;
  19. }
  20.            
  21. if (trueX < 0) {
  22.     eastBound = this.width - Math.abs(trueX);
  23.     westBound = Math.abs(trueX);
  24. } else {
  25.     eastBound = trueX;
  26.     westBound = this.width;
  27. }
  28.  
  29. if (rotAngle == 0) { //this is for when MC is created upright, rotating counter-clockwise
  30.     axisArray = [northBound, eastBound, southBound, westBound];
  31. } else if (rotAngle == 180) { //this is for when mc is created upside down, rotating counter-clockwise
  32.     axisArray = [southBound, westBound, northBound, eastBound];
  33. }
  34.  
  35.  
  36. //########## in your rotate function
  37. var standby:int = axisArray[0];
  38. axisArray.splice(0, 1);
  39. axisArray.push(standby);
  40.   //after your rotation tweening, run your checkBoundary() function to reposition the MC
  41. checkBoundary();
  42.  
  43.  
  44. //########## boundary checking function
  45. private function checkBoundary():void {
  46.     var buffer:int = 60;
  47.  
  48.     //northwards
  49.     if ((this.y - axisArray[0]) < 0) {
  50.         TweenLite.to(this, 0.3, {y:buffer + axisArray[0]});
  51.     //southwards
  52.     } else if ((this.y + axisArray[2]) > 1080) {
  53.         TweenLite.to(this, 0.3, {y:1080 - (buffer + axisArray[2])});
  54.     }
  55.            
  56.     //eastwards
  57.     if ((this.x + axisArray[3]) > 1920) {
  58.         TweenLite.to(this, 0.3, {x:1920 - (buffer + axisArray[3])});
  59.     //westwards
  60.     } else if ((this.x - axisArray[1]) < 0) {
  61.         TweenLite.to(this, 0.3, {x:buffer + axisArray[1]});
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement