我需要减速,然后停止使用AS3的影片剪辑动画。 单击停止按钮将触发减速。
任何人都知道一个很好的技术吗?我不能使用补间引擎来实现这种效果,因为它是一个拒绝这种类型库的学校项目。
答案 0 :(得分:1)
您可以控制MovieClip,而不是让它自由播放。
这是一个可以使用的课程
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class MovieClipController
{
private var _mc:MovieClip;
private var _playing:Boolean;
private var _speed:Number;
private var _currentFrame:Number;
public function MovieClipController( mc:MovieClip )
{
_mc = mc;
_mc.stop();
_currentFrame = _mc.currentFrame;
}
public function play( speed:Number = 1 ):void
{
if(!_playing) _mc.addEventListener(Event.ENTER_FRAME, handleEnterFrame );
_playing = true;
_speed = speed;
}
public function stop():void
{
if(_playing) _mc.removeEventListener(Event.ENTER_FRAME, handleEnterFrame );
_playing = false;
_mc.stop();
}
public function get speed():Number
{
return _speed;
}
private function handleEnterFrame(e:Event):void
{
if (_playing)
{
_currentFrame += _speed;
_mc.gotoAndStop( Math.round(_currentFrame % _mc.totalFrames) );
}
}
}
}
用法(假设myAnimation已添加到舞台中):
var myController:MovieCLipController = new MovieClipController( myAnimation );
...
myController.play(1.00); // plays animation at 100% speed
...
myController.play(0.50); // plays animation at 50% speed
...
myController.play(0.10); // plays animation at 10% speed, etc
...
myController.play( myController.speed * 0.90 ); // decrease speed by 10 percent.
...
myController.play( myController.speed - 0.10); // decrease speed by 10 percentage points
答案 1 :(得分:0)
您可以降低帧率:
stage.frameRate = N;
但请注意,这会降低整个SWF的帧率。
答案 2 :(得分:0)
最容易和最合乎逻辑的方法是拥有一个可以减少的velocity
属性。这是一个可以包含这样一个属性的类:
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class PhysicsMovieClip extends MovieClip
{
// Properties
private var _velocity:Number = 0;
private var _angle:Number = 0;
public var velocityTarget:Number = 0;
/**
* Constructor
*/
public function PhysicsMovieClip()
{
addEventListener(Event.ENTER_FRAME, _handle);
}
/**
* ...
* @param e Event.ENTER_FRAME
*/
private function _handle(e:Event):void
{
_velocity -= (_velocity - velocityTarget) / 10;
x += Math.cos(_angle) * _velocity;
y += Math.sin(_angle) * _velocity;
}
/**
* Getters & Setters
*/
public function get angle():Number{ return _angle * 180 / Math.PI; }
public function set angle(value:Number):void
{
_angle = value / 180 * Math.PI;
}
}
}
以上内容将允许您更改velocityTarget
属性,这会降低或加速您的对象。
示例:
var mc:PhysicsMovieClip = new PhysicsMovieClip(); // assign graphics somewhere
addChild(mc);
mc.velocityTarget = 10; // the MovieClip will speed up
您可以通过设置上面的angle
属性来改变移动方向:
mc.angle = 90; // movement is now directly south
mc.angle = 270 // movement is now directly north
(闪光灯直接向东0度)