Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //########## for stage boundary
- private var rotAngle:int; // THIS IS YOUR ROTATION ANGLE, DEFINE AT THE START BEFORE SETUP.
- private var axisArray:Array = [];
- private var trueX:int = -465;
- private var trueY:int = -17;
- private var northBound:int;
- private var southBound:int;
- private var eastBound:int;
- private var westBound:int;
- //########## during setup
- if (trueY < 0) {
- northBound = Math.abs(trueY);
- southBound = this.height - Math.abs(trueY);
- } else {
- northBound = 0;
- southBound = this.height;
- }
- if (trueX < 0) {
- eastBound = this.width - Math.abs(trueX);
- westBound = Math.abs(trueX);
- } else {
- eastBound = trueX;
- westBound = this.width;
- }
- if (rotAngle == 0) { //this is for when MC is created upright, rotating counter-clockwise
- axisArray = [northBound, eastBound, southBound, westBound];
- } else if (rotAngle == 180) { //this is for when mc is created upside down, rotating counter-clockwise
- axisArray = [southBound, westBound, northBound, eastBound];
- }
- //########## in your rotate function
- var standby:int = axisArray[0];
- axisArray.splice(0, 1);
- axisArray.push(standby);
- //after your rotation tweening, run your checkBoundary() function to reposition the MC
- checkBoundary();
- //########## boundary checking function
- private function checkBoundary():void {
- var buffer:int = 60;
- //northwards
- if ((this.y - axisArray[0]) < 0) {
- TweenLite.to(this, 0.3, {y:buffer + axisArray[0]});
- //southwards
- } else if ((this.y + axisArray[2]) > 1080) {
- TweenLite.to(this, 0.3, {y:1080 - (buffer + axisArray[2])});
- }
- //eastwards
- if ((this.x + axisArray[3]) > 1920) {
- TweenLite.to(this, 0.3, {x:1920 - (buffer + axisArray[3])});
- //westwards
- } else if ((this.x - axisArray[1]) < 0) {
- TweenLite.to(this, 0.3, {x:buffer + axisArray[1]});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement