ActionScript MovieClip 向左移动,但不向右移动
我有一个带有实例名称为“mc”的影片剪辑的舞台。目前我有一个代码应该左右移动玩家,当释放左键或右键时,“mc”会滑动一点。我遇到的问题是,使“mc”向左移动可以,但用于右侧的某些代码却不能。
所有这些代码都出现在主舞台 - 第一帧上,
//Variables
var mcSpeed:Number = 0;//MC's Current Speed
var mcJumping:Boolean = false;//if mc is Jumping
var mcFalling:Boolean = false;//if mc is Falling
var mcMoving:Boolean = false;//if mc is Moving
var mcSliding:Boolean = false;//if mc is sliding
var mcSlide:Number = 0;//Stored for use when creating slide
var mcMaxSlide:Number = 1.6;//Max Distance the object will slide.
//Player Move Function
p1Move = new Object();
p1Move = function (dir:String, maxSpeed:Number) {
if (dir == "left" && _root.mcSpeed<maxSpeed) {
_root.mcSpeed += .2;
_root.mc._x -= _root.mcSpeed;
} else if (dir == "right" && _root.mcSpeed<maxSpeed) {
_root.mcSpeed += .2;
_root.mc._x += _root.mcSpeed;
} else if (dir == "left" && speed>=maxSpeed) {
_root.mc._x -= _root.mcSpeed;
} else if (dir == "right" && _root.mcSpeed>=maxSpeed) {
_root.mc._x += _root.mcSpeed;
}
}
//onEnterFrame for MC
mc.onEnterFrame = function():Void {
if (Key.isDown(Key.LEFT)) {
if (_root.mcMoving == false && _root.mcSliding == false) {
_root.mcMoving = true;
} else if (_root.mcMoving == true && _root.mcSliding == false) {
_root.p1Move("left",5);
}
} else if (!Key.isDown(Key.LEFT)) {
if (_root.mcMoving == true && _root.mcSliding == false) {
_root.mcSliding = true;
} else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide<_root.mcMaxSlide) {
_root.mcSlide += .2;
this._x -= .2;
} else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide>=_root.mcMaxSlide) {
_root.mcMoving = false;
_root.mcSliding = false;
_root.mcSlide = 0;
_root.mcSpeed = 0;
}
} else if (Key.isDown(Key.RIGHT)) {
if (_root.mcMoving == false && _root.mcSliding == false) {
_root.mcMoving = true;
} else if (_root.mcMoving == true && _root.mcSliding == false) {
_root.p1Move("right",5);
}
} else if (!Key.isDown(Key.RIGHT)) {
if (_root.mcMoving == true && _root.mcSliding == false) {
_root.mcSliding = true;
} else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide<_root.mcMaxSpeed) {
_root.mcSlide += .2;
this._x += .2;
} else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide>=_root.mcMax) {
_root.mcMoving = false;
_root.mcSliding = false;
_root.mcSlide = 0;
_root.mcSpeed = 0;
}
}
};
我只是不明白为什么当您按向左箭头时它工作得很好,但当您按向右箭头时它没有响应。这实际上是相同的代码。
I have a stage with a movie clip with the instance name of "mc". Currently I have a code that is suppose to move the player left and right, and when the left or right key is released, the "mc" slides a little bit. The problem I'm having is that making the "mc" move to the left works, but the exact some code used for the right doesn't.
All of this code is present on the Main Stage - Frame One
//Variables
var mcSpeed:Number = 0;//MC's Current Speed
var mcJumping:Boolean = false;//if mc is Jumping
var mcFalling:Boolean = false;//if mc is Falling
var mcMoving:Boolean = false;//if mc is Moving
var mcSliding:Boolean = false;//if mc is sliding
var mcSlide:Number = 0;//Stored for use when creating slide
var mcMaxSlide:Number = 1.6;//Max Distance the object will slide.
//Player Move Function
p1Move = new Object();
p1Move = function (dir:String, maxSpeed:Number) {
if (dir == "left" && _root.mcSpeed<maxSpeed) {
_root.mcSpeed += .2;
_root.mc._x -= _root.mcSpeed;
} else if (dir == "right" && _root.mcSpeed<maxSpeed) {
_root.mcSpeed += .2;
_root.mc._x += _root.mcSpeed;
} else if (dir == "left" && speed>=maxSpeed) {
_root.mc._x -= _root.mcSpeed;
} else if (dir == "right" && _root.mcSpeed>=maxSpeed) {
_root.mc._x += _root.mcSpeed;
}
}
//onEnterFrame for MC
mc.onEnterFrame = function():Void {
if (Key.isDown(Key.LEFT)) {
if (_root.mcMoving == false && _root.mcSliding == false) {
_root.mcMoving = true;
} else if (_root.mcMoving == true && _root.mcSliding == false) {
_root.p1Move("left",5);
}
} else if (!Key.isDown(Key.LEFT)) {
if (_root.mcMoving == true && _root.mcSliding == false) {
_root.mcSliding = true;
} else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide<_root.mcMaxSlide) {
_root.mcSlide += .2;
this._x -= .2;
} else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide>=_root.mcMaxSlide) {
_root.mcMoving = false;
_root.mcSliding = false;
_root.mcSlide = 0;
_root.mcSpeed = 0;
}
} else if (Key.isDown(Key.RIGHT)) {
if (_root.mcMoving == false && _root.mcSliding == false) {
_root.mcMoving = true;
} else if (_root.mcMoving == true && _root.mcSliding == false) {
_root.p1Move("right",5);
}
} else if (!Key.isDown(Key.RIGHT)) {
if (_root.mcMoving == true && _root.mcSliding == false) {
_root.mcSliding = true;
} else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide<_root.mcMaxSpeed) {
_root.mcSlide += .2;
this._x += .2;
} else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide>=_root.mcMax) {
_root.mcMoving = false;
_root.mcSliding = false;
_root.mcSlide = 0;
_root.mcSpeed = 0;
}
}
};
I just don't get why when you press the left arrow its works completely fine, but when you press the right arrow it doesn't respond. It is literally the same code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于循环代码,您从未阅读过它:
使用
if(keyright)
而不是else if
,它应该可以工作。you never read it because of your loop code:
use
if(keyright)
instead ofelse if
and it should work.