[as3]as3实现屏幕切换震动的效果 as3屏幕
[as3]as3实现屏幕切换震动的效果 as3屏幕
[as3]as3实现屏幕切换震动的效果 as3屏幕
- package tools {
- import flash.display.DisplayObject;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- public class Earthquake {
- /**
- * 参数
- */
- private var _timer:Timer;
- private var _displayObject:DisplayObject;
- private var _originalX:int;
- private var _originalY:int;
- private var _intensity:int;
- private var _intensityOffset:int;
- /**
- * 时间
- */
- private var _seconds:Number;
- /**
- * 方向
- */
- public static const LEFT_RIGHT_UP_DOWN:int = 0;
- public static const LEFT_RIGHT:int = 1;
- public static const UP_DOWN:int = 2;
- /**
- * 帧频
- */
- public static const FRAME_RATE:int = 60;
- /**
- * 方向
- */
- private var _direction:int;
- /**
- * 震动中
- */
- private var _bShaking:Boolean = false;
- /**
- * 是否自动销毁
- */
- private var _bDestroy:Boolean = false;
- /**
- * 对一个显示对象应用地震效果。
- * @param displayObject 抖动对象
- * @param intensity 强度
- * @param seconds 持续时间 秒
- * @param direction 方向
- * @param autoDestroy 自动销毁
- */
- public function Earthquake(displayObject:DisplayObject, intensity:Number = 10, seconds:Number = 1, direction:int = 0, autoDestroy:Boolean = false):void
- {
- _displayObject = displayObject;
- _originalX = displayObject.x;
- _originalY = displayObject.y;
- _intensity = intensity;
- _intensityOffset = intensity / 2;
- _seconds = seconds;
- _direction = direction;
- _bDestroy = autoDestroy;
- }
- /**
- * 开始后抖动
- */
- public function go():void
- {
- if (_bShaking) return;
- _bShaking = true;
- var msPerUpdate:int = int(1000 / FRAME_RATE);
- var totalUpdates:int = int(_seconds * 1000 / msPerUpdate);
- if (!_timer)
- {
- _timer = new Timer(msPerUpdate, totalUpdates);
- _timer.addEventListener(TimerEvent.TIMER, quake);
- _timer.addEventListener(TimerEvent.TIMER_COMPLETE, resetImage);
- }
- else
- {
- _displayObject.x = _originalX;
- _displayObject.y = _originalY;
- _timer.reset();
- }
- _timer.start();
- }
- /**
- * 抖动
- * @param event
- */
- private function quake( event:TimerEvent ):void
- {
- var newX:int = _originalX;
- var newY:int = _originalY;
- switch(_direction)
- {
- case LEFT_RIGHT_UP_DOWN:
- newX = _originalX + Math.random() * _intensity - _intensityOffset;
- newY = _originalY + Math.random() * _intensity - _intensityOffset;
- break;
- case LEFT_RIGHT:
- newX = _originalX + Math.random() * _intensity - _intensityOffset;
- break;
- case UP_DOWN:
- newY = _originalY + Math.random() * _intensity - _intensityOffset;
- break;
- }
- _displayObject.x = newX;
- _displayObject.y = newY;
- }
- /**
- * 重置
- * @param event
- */
- private function resetImage( event:TimerEvent = null ):void
- {
- _displayObject.x = _originalX;
- _displayObject.y = _originalY;
- cleanup();
- }
- /**
- * 清除
- */
- private function cleanup():void
- {
- _bShaking = false;
- /*_timer = null;
- _timer.stop();*/
- _timer.reset();
- if (_bDestroy)
- {
- _timer.removeEventListener(TimerEvent.TIMER, quake);
- _timer.removeEventListener(TimerEvent.TIMER_COMPLETE, resetImage);
- _timer = null;
- _displayObject = null;
- }
- delete [this];
- //_displayObject = null;
- }
- }
- }
[as3]as3实现屏幕切换震动的效果 as3屏幕
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...