cocosCreator JS 开发 之 预制资源使用Prefab

本文介绍了在cocosCreator中如何制作和使用Prefab,详细阐述了Prefab的制作过程、预制板脚本绑定、加载使用的方法。在实践过程中,针对遇到的点击事件处理问题,提出了解决方案——通过添加遮罩层监听点击事件来销毁节点。此外,文章还探讨了如何在Prefab中传递参数,并提供了关于按钮响应和定时功能的拓展思路。
摘要由CSDN通过智能技术生成

1、Prefab制作

 ->制作教程:https://docs.cocos.com/creator/manual/zh/asset-workflow/prefab.html

2、编写一个预制板脚本绑定

/*
    通用提示框
*/

cc.Class({
    extends: cc.Component,
 
    properties: {
        Text: { default: null, type: cc.Label },
        showTimes: 1, //隐藏时间
        jumpHeight: 100, //跳跃高度
        _isShow:false,
    },
 
    // LIFE-CYCLE CALLBACKS:
    setLabelString: function( str )
    {
        //這邊直接將我們的Label字串設定為 No.#
        //this.Text.string = ( str );
        //cc.find("background/textCount").getComponent(cc.Label).string = str;
        this.node.getChildByName("Text").getComponent(cc.Label).string = str;
    },
 
    //按钮点击回调
    onConfirBtn:function(callback){
        console.log("发布按钮点击回调事件");
        this.node.getChildByName("btnconfir").on('click',function(event){
            console.log("点击到按钮");
            callback();
        },this);
    },

    onLoad:function () {
        cc.log("showTips.onLoad")
        window.showtips = this;
 
        // 初始化计时器
        this.timer = 0;
        this.node.active = true;

        this.node.getChildByName("layout").on('
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值