egret之弹幕
2024-09-01 03:31:30
要实现弹幕功能,首先需要将弹幕配置成配置表。然后代码随机生成。
/**生成单个弹幕 */
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函数
最新文章
- servlet 简介,待完善
- Windows 10 内置管理员无法打开Metro应用方法
- SQLServer并发问题,先SELECT后UPDATE,避免并发脏读情况解决
- leetcode-188 买卖股票4
- iOS开发——高级技术精选&;底层开发之越狱开发第一篇
- MySQL版本调研
- SQL从入门到基础 - 02 SQLServer的使用
- NET基础课--应用程序编译和执行1
- 网易云课堂_程序设计入门-C语言_第七周:指针与字符串_2GPS数据处理
- [转载] python利用psutil遍历进程名字和exe所在目录
- QCW切割 --铁片
- Grafana+Prometheus系统监控之MySql
- S5PV210中断处理
- C# Excel添加超链接
- Scrapy学习篇(一)之框架
- zw版【转发·台湾nvp系列Delphi例程】HALCON SmallestRectangle2
- JavaScript权威指南(第6版)(中文版)笔记
- bacula备份终端操作bconsole指令
- 扯不清楚的virtual和abstract
- gulp快速将css中的px替换成rem