Flash 闪烁-轻松推出滚动moviclip,由两侧的传感器滚动
我希望有人能为我解释一下这个问题。。。我有一个电影唇,通过舞台两侧的“传感器”滚动。剪辑在两个方向上都可以正常滚动,但我的问题是: 当用户鼠标离开舞台时,电影剪辑停止在其轨迹中,这无法提供良好的平滑效果。看看下面的代码,我有没有办法告诉动画在用户鼠标离开舞台时放松,而不是突然停止Flash 闪烁-轻松推出滚动moviclip,由两侧的传感器滚动,flash,actionscript,actionscript-2,Flash,Actionscript,Actionscript 2,我希望有人能为我解释一下这个问题。。。我有一个电影唇,通过舞台两侧的“传感器”滚动。剪辑在两个方向上都可以正常滚动,但我的问题是: 当用户鼠标离开舞台时,电影剪辑停止在其轨迹中,这无法提供良好的平滑效果。看看下面的代码,我有没有办法告诉动画在用户鼠标离开舞台时放松,而不是突然停止 class Sensor extends MovieClip { public function Sensor() { } public function onEnterFrame() {
class Sensor extends MovieClip {
public function Sensor() {
}
public function onEnterFrame() {
//
var active:Boolean;
// is mouse within sensor?
if ((_level2._xmouse >= this._x) && _level2._xmouse <= (this._x + this._width)) {
active = true;
} else {
active = false;
}
if(active) {
// which area of the sensor is it in?
var relative_position:Number;
var relative_difference:Number;
relative_position = _level2._xmouse / this._width * 100.0;
//_level2._logger.message("relative position is " + relative_position);
if (!isNaN(relative_position)) {
// depending on which area it is in, tend towards a particular adjustment
if(relative_position > _level2._background_right_threshold) {
relative_difference = Math.abs(relative_position - _level2._background_right_threshold);
//relative_difference = 10;
} else if(relative_position < _level2._background_left_threshold) {
relative_difference = Math.abs(_level2._background_left_threshold - relative_position);
relative_difference *= -1;
} else {
_level2._background_ideal_adjustment = 0;
}
var direction:Number;
if(_level2._pan_direction == "left") {
direction = 1;
} else {
direction = -1;
}
_level2._background_ideal_adjustment = direction * (relative_difference / 10) * _level2._pan_augmentation;
//_level2._logger.message("ideal adjustment is " + _level2._background_ideal_adjustment);
if (!isNaN(_level2._background_ideal_adjustment)) {
// what is the difference between the ideal adjustment and the current adjustment?
// add a portion of the difference to the adjustment:
// this has the effect that the adjustment "tends towards" the ideal
var difference:Number;
difference = _level2._background_ideal_adjustment - _level2._background_adjustment;
_level2._background_adjustment += (difference / _level2._background_tension);
// calculate what the new background _x position would be
var background_x:Number;
var projected_x:Number;
background_x = _level2["_background"]._x;
projected_x = background_x += _level2._background_adjustment;
//_level2._logger.message("projected _x is " + projected_x);
// if the _x position is valid, change it
if(projected_x > 0) projected_x = 0;
if(projected_x < -(_level2["_background"]._width - Stage.width)) projected_x = -(_level2["_background"]._width - Stage.width);
_level2["_background"]._x = projected_x;
// i recommend that you move your other movieclips with code here
}
}
}
}
}
class传感器扩展了MovieClip{
公共功能传感器(){
}
公共函数onEnterFrame(){
//
var-active:布尔型;
//鼠标在传感器内吗?
如果((_level2._xmouse>=this._x)和&u level2._xmouse._level2._background_right_threshold){
相对差值=数学abs(相对位置-\u级别2.\u背景\u右\u阈值);
//相对_差=10;
}否则如果(相对位置<水平2.\u背景\u左\u阈值){
相对差值=数学绝对值(_level2._background_left_threshold-相对位置);
相对_差*=-1;
}否则{
_级别2.\u背景\u理想\u调整=0;
}
var方向:数值;
如果(_level2._pan_direction==“left”){
方向=1;
}否则{
方向=-1;
}
_级别2.\u背景\u理想\u调整=方向*(相对\u差异/10)*\u级别2.\u平移\u增大;
//_level2.\u logger.message(“理想调整为”+\u level2.\u后台\u理想调整);
如果(!isNaN(_level2._background_ideal_adjustment)){
//理想调整和当前调整之间有什么区别?
//将部分差额添加到调整中:
//这就产生了调整“趋向”理想的效果
var差:个数;
差异=_level2._background_ideal_adjustment-_level2._background_adjustment;
_级别2.背景调整+=(差异/级别2.背景张力);
//计算新的背景位置
变量背景x:数字;
变量x:数值;
背景x=_level2[“_background”]。_x;
预计的\u x=背景\u x+=\u级别2.\u背景\u调整;
//_level2._logger.message(“projected_x is”+projected_x);
//如果x位置有效,请更改它
如果(投影_x>0)投影_x=0;
如果(投影的_x<-(2级[“2背景]。2宽度-舞台宽度))投影的_x=-(2级[“2背景]。2宽度-舞台宽度);
_第二级[“_背景”]。_x=预计的_x;
//我建议你在这里用代码移动你的其他电影嘴唇
}
}
}
}
}
您提供的链接不起作用,但我想我有一点建议
velocity=0;
maxVelocity=3;
accel=0.1;
break=0.98;
function onEnterFrame(){
if (mouseOverRightSensor){
velocity +=accel;
}else if (mouseOverLeftSensor){
velocity -=accel;
}
// make sure you constrain the velocity
if (Math.abs(velocity)>maxVelocity) {
//get the sign of the velocity and multiply it with maxVelocity
velocity=Math.abs(velocity)/velocity * maxVelocity
}
//Add the velocity to the movieclip's position
movieclip.x+=velocity;
//shrink down the velocity, this is done each frame no matter if the mouse is over the sensor;
velocity*=break;
}
基本上,即使鼠标不在传感器上,也需要移动movieclip。这可以通过使用速度变量来实现
您可能需要调整值并添加更多代码,这只是一些概念代码。
希望它能帮助您:)谢谢,这似乎是最好的路线。链接不再工作,抱歉。再次感谢。