博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
白鹭震屏效果
阅读量:6550 次
发布时间:2019-06-24

本文共 4011 字,大约阅读时间需要 13 分钟。

hot3.png

class ShakeTool1 {    private static instance: ShakeTool1;   //单例    public static getInstance(): ShakeTool1 {        if (this.instance == null) {            this.instance = new ShakeTool1();        }        return this.instance;    }    private checkForMinimumValues: boolean = true;    private minShakeValue: number = 0.001;    private minRotationValue: number = 0.001;    /**屏幕震动 */    public ShakeScreen() {        Main.Instance.getSceneRoot().x = 0        Main.Instance.getSceneRoot().y = 0        ShakeTool1.getInstance().DoShake_Internal(Main.Instance.getSceneRoot(),            2, //震动次数            new egret.Point(0.5, 0.5), //x,y轴的震动系数[-1,1]            new egret.Point(1, 1), //x,y轴的震动量级            0,  //旋转量级             8, //震动x.y轴的最大偏移量            50, //如果速度越快,则振幅越剧烈            1 //振幅的递减系数        )    }	/**	 * 屏幕震动	 * @param camera 震动对象	 * @param numberOfShakes 震动次数	 * @param seed   x,y轴的震动系数[-1,1]	 * @param shakeAmount  x,y轴的震动量级	 * @param rotationAmount  旋转量级  如果小于0表示:不旋转	 * @param distance   震动x.y轴的最大偏移量	 * @param speed 如果速度越快,则振幅越剧烈	 * @param decay 振幅的递减系数	 * @param endCallBack 结束回调	 * 	 */    public DoShake_Internal(cam: egret.DisplayObject, numberOfShakes: number, seed: egret.Point, shakeAmount: egret.Point,        rotationAmount: number, distance: number, speed: number,        decay: number, endCallBack: Function = null) {        if (cam == null)            return        var defaultPointY = cam.x        var defaultPointX = cam.y        var defaultRotation = cam.rotation        // Set random values        var mod1 = seed.x > 0.5 ? 1 : -1;        var mod2 = seed.y > 0.5 ? 1 : -1;        var currentShakes = numberOfShakes        var shakeDistance = distance;        let shakePosition: egret.Point        let shakeRotation: egret.Point        let guiShakePosition: egret.Point        let rotationStrength = 1;        let start1: egret.Point = new egret.Point(0, 0)        let startR: egret.Point = new egret.Point(0, 0)        let startTime = 0        let timeOnEnterFrame = -1        let curTime: number = 0        let resetEvent = () => {            cam.x = defaultPointY            cam.y = defaultPointY            cam.rotation = defaultRotation            cam.removeEventListener(egret.Event.ENTER_FRAME, updateEvent, this)            if (endCallBack != null) {                endCallBack()            }        }        let updateEvent = () => {            var now = egret.getTimer();            var time = timeOnEnterFrame;            var pass = (now - time) / 1000;            if (timeOnEnterFrame == -1) {                timeOnEnterFrame = now;                return            }            else {                timeOnEnterFrame = now;            }            curTime += pass            curTime = curTime * speed            if (this.checkForMinimumValues) {                if (rotationStrength <= this.minRotationValue) {                    resetEvent()                    return                }                if (distance != 0 && shakeDistance <= this.minShakeValue) {                    resetEvent()                    return;                }                if (currentShakes <= 0) {                    resetEvent()                    return;                }            }            if (cam == null) {                return            }            cam.x = defaultPointY + mod1 * Math.sin(curTime) * (shakeAmount.x * shakeDistance)            cam.y = defaultPointX + mod2 * Math.cos(curTime) * (shakeAmount.y * shakeDistance)            if (rotationAmount > 0) {                cam.rotation = defaultRotation + Math.cos(curTime) * (rotationAmount * rotationStrength)            }            if (curTime > Math.PI * 2) {                curTime = 0;                shakeDistance *= (1 - Tools.Mathf.Clamp01(decay));                rotationStrength *= (1 - Tools.Mathf.Clamp01(decay));                currentShakes--;            }        }        cam.addEventListener(egret.Event.ENTER_FRAME, updateEvent, this);    }}

 

转载于:https://my.oschina.net/u/698044/blog/3000346

你可能感兴趣的文章
CNBC:现在是时候购买BCH了
查看>>
2018-11-29学习笔记
查看>>
【2018.04.18学习笔记】【linux基础知识7.1-7.5】
查看>>
Python基础——内置hashlib、IO、Json、codecs模块(0426)
查看>>
企业级 SpringBoot教程(三)SpringBoot用JdbcTemplates访问Mysql
查看>>
find命令,文件后缀名
查看>>
Illegal modifier for parameter s; only final is permitted
查看>>
多线程系列六:线程池
查看>>
5 月编程语言排行榜:Java第一,R跌出Top20
查看>>
使用SpringMVC的@Validated注解验证
查看>>
DDoS攻击新趋势:海量移动设备成为新一代肉鸡
查看>>
超详细的SN74LVC14ADR介绍,就在这里
查看>>
阿里云Redis读写分离典型场景:如何轻松搭建电商秒杀系统
查看>>
手把手教你设计一个百万级的消息推送系统
查看>>
关于请求被挂起页面加载缓慢问题的追查
查看>>
Python之父重回决策层,社区未来如何发展?
查看>>
Git管理代码:Git简介与安装、配置(一)
查看>>
Flutter 实现原理及在马蜂窝的跨平台开发实践
查看>>
Linux平台下可视化压测软件visual-wrk
查看>>
我的提交信息规范
查看>>