ActionScript 影片剪辑向左移动,但不向右移动
Posted
技术标签:
【中文标题】ActionScript 影片剪辑向左移动,但不向右移动【英文标题】:ActionScript MovieClip moves to the left, but not the right 【发布时间】:2011-02-10 21:01:54 【问题描述】:我有一个带有实例名称为“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;
;
我只是不明白为什么当你按左箭头时它工作得很好,但是当你按右箭头时它没有响应。它实际上是相同的代码。
【问题讨论】:
【参考方案1】:因为你的循环代码,你从来没有读过它:
if(keyleft)
//catches all keyleft
else if(!keyleft)
//katches all non key left
else if(keyright)
//Never called because all eventualities have been covered by the above.
使用if(keyright)
而不是else if
,它应该可以工作。
【讨论】:
以上是关于ActionScript 影片剪辑向左移动,但不向右移动的主要内容,如果未能解决你的问题,请参考以下文章