内容简介:看代码(Typescript):
看代码(Typescript):
import { AnalyzeJSON } from "./AnalyzeJSON";
const {ccclass, property} = cc._decorator;
@ccclass
export class Dialog extends cc.Component {
@property({type:cc.Float, tooltip:"播放速度"})
playSpeed:number = 0;
_speed:number;
_dialogLabel:cc.Label = null; //文本框
_contentStr:string = ""; //当前播放的内容
_currTextIndex:number = 0; //当前播放内容的索引
_currDialogIndex:number = 0; //当前对话列表的索引
_isPlaying:boolean = false; //是否正在播放
_contentList:Array<string> = null; //谈话内容
_endEvent:Function = null; //结束处理事件
onLoad () {
this._dialogLabel = this.node.getComponentInChildren(cc.Label);
this.node.on(cc.Node.EventType.TOUCH_END, this._onClickBox, this);
}
/**点击跳过打字机效果 */
_onClickBox():void{
if(this._isPlaying){
this._dialogLabel.string = this._contentStr;
this._reset();
}else{
//对话是否结束 TODO
this._currDialogIndex++;
if(this._contentList[this._currDialogIndex] == null)
this._currDialogIndex = 0;
this.playDialog(this._contentList[this._currDialogIndex]);
}
}
start () {
this._speed = this.playSpeed;
this._contentList = AnalyzeJSON._instance.getDialog(); //从管理器里读取要显示的对话
this.playDialog(this._contentList[this._currDialogIndex]);
}
update (dt) {
//#region 打字机效果
if(this._isPlaying){
this._speed -= dt;
if(this._speed <= 0){
this._speed = this.playSpeed;
if(this._contentStr[this._currTextIndex] == null){
this._reset();
}else{
this._addText(this._contentStr[this._currTextIndex]);
this._currTextIndex++;
}
}else return;
}
//#endregion
}
/**开始对话 */
playDialog(str:string, callback?:Function):void{
this._isPlaying = true;
this._contentStr = str;
this._clearContent();
if(callback)
this._endEvent = callback;
}
/**设置速度 */
setSpeed(val:number):void{
this.playSpeed = val;
}
/**重置内容 */
_reset():void{
this._isPlaying = false;
this._contentStr = "";
this._currTextIndex = 0;
this._speed = this.playSpeed;
}
/**清除对话框内容 */
_clearContent():void{
this._dialogLabel.string = "";
}
/**添加文字 */
_addText(aStr:string):void{
this._dialogLabel.string += aStr;
}
}
以上所述就是小编给大家介绍的《游戏开发之——对话系统(CocosCreator)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- Android音频开发——对讲机实时语音对话
- python与html5 websocket开发聊天对话窗
- 对话 Tetrate.io 创始工程师吴晟:开源领域需要 40+ 的开发者,也需要更张扬的年轻人
- 读懂智能对话系统:智能对话的未来
- 读懂智能对话系统(1)任务导向型对话系统
- AAAI 2020论文分享 | 基于知识图谱进行对话目标规划的开放域对话生成技术
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
精通数据科学:从线性回归到深度学习
唐亘 / 人民邮电出版社 / 2018-5-8 / 99.00元
数据科学是一门内涵很广的学科,它涉及到统计分析、机器学习以及计算机科学三方面的知识和技能。本书深入浅出、全面系统地介绍了这门学科的内容。 本书分为13章,最初的3章主要介绍数据科学想要解决的问题、常用的IT工具Python以及这门学科所涉及的数学基础。第4-7章主要讨论数据模型,主要包含三方面的内容:一是统计中最经典的线性回归和逻辑回归模型;二是计算机估算模型参数的随机梯度下降法,这是模型工......一起来看看 《精通数据科学:从线性回归到深度学习》 这本书的介绍吧!