要实现弹幕功能,首先需要将弹幕配置成配置表。然后代码随机生成。

        /**生成单个弹幕 */
private showCaptionAnim(captionText: string) {
egret.log("字幕生成");
var showCaption_1: egret.TextField = new egret.TextField();
showCaption_1.text = captionText;
showCaption_1.textColor = 0Xffffff;
showCaption_1.size = ;
showCaption_1.x = this.stage.stageWidth - ;
showCaption_1.y = Fight.GameUtil.getRandomInt(this.gameScene.gamePanel.curNPC.y, this.gameScene.gamePanel.y + this.gameScene.gamePanel.curNPC.height / ) - ;
this.gameScene.gamePanel.captionGroup.visible = true;
if (this.gameScene.gamePanel.captionGroup) {
this.gameScene.gamePanel.captionGroup.addChild(showCaption_1);
// this.gameScene.gamePanel.captionGroup.visible = false;
}
this.captionMove(showCaption_1);
} /**控制单个弹幕的移动 */
private captionMove(text: egret.TextField) {
if (text != undefined && text != null) {
let random = Math.floor(Math.random() * + );
egret.Tween.get(text).to({ x: - }, random * ).call(() => {
egret.Tween.removeTweens(text);
});
}
}
/**随机弹幕 */
private randomCaption() {
//取配置表中的所有弹幕,通过/分割成数组
let str = GameData.CfgsData.caption.split("/"); //弹幕概率随机
let num1 = Math.floor(Math.random() * );//0-9
//0---true other----false
if (num1 == ) {
this.isCaption = true;
} else {
this.isCaption = false;
}
if (this.isCaption) {
let index = Math.floor(Math.random() * str.length);//随机弹幕数组下标
let currCaption = str[index].toString();
this.showCaptionAnim(currCaption);
}
}

在需要调用弹幕的时候调用randomCaption函数

最新文章

  1. servlet 简介,待完善
  2. Windows 10 内置管理员无法打开Metro应用方法
  3. SQLServer并发问题,先SELECT后UPDATE,避免并发脏读情况解决
  4. leetcode-188 买卖股票4
  5. iOS开发——高级技术精选&底层开发之越狱开发第一篇
  6. MySQL版本调研
  7. SQL从入门到基础 - 02 SQLServer的使用
  8. NET基础课--应用程序编译和执行1
  9. 网易云课堂_程序设计入门-C语言_第七周:指针与字符串_2GPS数据处理
  10. [转载] python利用psutil遍历进程名字和exe所在目录
  11. QCW切割 --铁片
  12. Grafana+Prometheus系统监控之MySql
  13. S5PV210中断处理
  14. C# Excel添加超链接
  15. Scrapy学习篇(一)之框架
  16. zw版【转发·台湾nvp系列Delphi例程】HALCON SmallestRectangle2
  17. JavaScript权威指南(第6版)(中文版)笔记
  18. bacula备份终端操作bconsole指令
  19. 扯不清楚的virtual和abstract
  20. gulp快速将css中的px替换成rem

热门文章

  1. Linux 安装MySql——ubuntu版
  2. C#读取Modbus数据
  3. Python_我的学习笔记 (博客停更------)
  4. nodejs 如何自动化配置环境参数
  5. Spring 整合 ibatis
  6. 图解Redis之数据结构篇——整数集合
  7. gulp压缩js文件报错日志
  8. CountDownLatch实现多线程并发请求
  9. 自定义SWT控件一之自定义单选下拉框
  10. 深入理解JVM-类加载器深入解析(3)