游戏开发之——对话系统(CocosCreator)

本文探讨了如何在CocosCreator中构建对话系统,重点在于使用Typescript进行编程实现。通过阅读代码,读者可以了解到游戏对话逻辑、角色交互和事件触发等方面的关键技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

看代码(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{
           
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值