I keep having trouble getting things to scale correctly when keys are pressed. I have included my code below. Please help this has been driving me nuts for days.
I did manage to get it working in only 4 directions, but when I added diagonals I had to workaround, and it’s not going too well.
Sometimes the character will scale erratically
[AS]
onClipEvent(load){stopper = 3; frame = 1}
//MOVEMENT//
onClipEvent(enterFrame){
// LEFT //
if (Key.isDown(Key.LEFT) & !Key.isDown(Key.UP) & !Key.isDown(Key.DOWN) & !Key.isDown(Key.RIGHT)){this.gotoAndStop(2); xspeed = -15; yspeed = 0; scalex = 0; scaley = 0; stopper = 4}
// RIGHT //
else if (Key.isDown(Key.RIGHT) & !Key.isDown(Key.UP) & !Key.isDown(Key.DOWN) & !Key.isDown(Key.LEFT)){this.gotoAndStop(1); xspeed = 15; yspeed = 0; scalex = 0; scaley = 0; stopper = 3}
// UP //
else if (Key.isDown(Key.UP) & !Key.isDown(Key.LEFT) & !Key.isDown(Key.RIGHT) & !Key.isDown(Key.DOWN) & _root.guymain._y > 30 + ymodifier){this.gotoAndStop(5);yspeed = -5; xspeed = 0; scaley = -1.2; scalex = -1.2; stopper = 7}
else if (Key.isDown(Key.UP) & !Key.isDown(Key.LEFT) & !Key.isDown(Key.RIGHT) & !Key.isDown(Key.DOWN)){this.gotoAndStop(5) ; xspeed = 0}
// DOWN //
else if (Key.isDown(Key.DOWN) & !Key.isDown(Key.LEFT) & !Key.isDown(Key.RIGHT) & !Key.isDown(Key.UP) & _root.guymain._y < 250){this.gotoAndStop(6); yspeed = 5; xspeed = 0; this._yscale +=1.2; this._xscale +=1.2; stopper = 8}
else if (Key.isDown(Key.DOWN) & !Key.isDown(Key.LEFT) & !Key.isDown(Key.RIGHT) & !Key.isDown(Key.UP)) {this.gotoAndStop(6) ; xspeed=0; stopper = 8}
// UP + LEFT //
else if (Key.isDown(Key.UP) & Key.isDown(Key.LEFT) & !Key.isDown(Key.RIGHT) & !Key.isDown(Key.DOWN) & _root.guymain_Y > 30){this.gotoAndStop(9); yspeed = -2.5; xspeed = -7.5; scalex = -1.1; scaley = -1.1}
// NOTHING //
else if (!Key.isDown(Key.LEFT) & !Key.isDown(Key.RIGHT) & !Key.isDown(Key.UP) & !Key.isDown(Key.DOWN)){xspeed = 0; yspeed = 0; scalex = 0; scaley = 0; this.gotoAndStop(stopper);}
else {speed=0; yspeed=0}
_root.guymain._x += xspeed
_root.guymain._y += yspeed
this._xscale += scalex
this._yscale += scaley
}
//COLLISION AND LIMITS//
onClipEvent(enterFrame){
if (_root.guymain._y > 250){_root.guymain._y = 250}
if (_root.guymain._y < 30 + ymodifier){_root.guymain._y = 30 + ymodifier}
if (_root.guymain._x < -95 && frame < 2){_root.guymain._x = -95}
if (_root.guymain._x > 423){_root.guymain._x = 423}
}
//SCENE CHANGING//
onClipEvent(enterFrame){
if (_root.guymain._x > 422 && frame == 1){_root.guymain._x = -95; frame ++; this._xscale = 100; this._yscale = 100; _root.guymain._y = 251}
if (frame == 1){_root.scene.gotoAndStop(frame); ymodifier = 0}
if (_root.guymain._x < -95 && frame == 2){_root.guymain._x = 421; frame --; this._xscale = 100; this._yscale = 100; _root.guymain._y = 251}
if (frame == 2){_root.scene.gotoAndStop(frame); ymodifier = 100}
}
[/AS]