Cocos Creator--1.介绍

Cocos Creator系列文章目录

Cocos Creator–1.介绍

Cocos Creator-2.UI系统

Cocos Creator-3.缓冲系统,动作系统,计时器

Cocos Creator-4.监听,发射事件,节点系统事件,全局系统事件

Cocos Creator-5.物理与碰撞系统

Cocos Creator-6.TS-属性检查器


前言

这里我主要是写代码,以及小游戏的制作,以及一个代码库的收集。

提示:以下是本篇文章正文内容,下面案例可供参考

一、简介?

看官网去!!!

Cocos Creator API

二、第一阶段问题

1.加载和切换场景(场景加载回调)

onbtn(){
   // cc.director.loadScene("Main")//跳转到游戏场景
   cc.director.loadScene("Main", this.onSceneLaunched);
}

onSceneLaunched(){
   console.log("这是回调函数")
}

2.音频播放(三种)

在这里插入图片描述

2.1.使用 AudioSource 组件播放

在这里插入图片描述

代码如下(示例):

2.2.通过脚本控制 AudioSource 组件

tanren:cc.AudioSource=null;//背景音乐

this.tanren= this.getComponent(cc.AudioSource);
this.tanren.play();//播放
this.tanren.pause();//结束

2.3.通过脚本控制 AudioSource 组件(官方推荐的)

@property(cc.AudioClip)
    tanren1:cc.AudioClip=null;//背景音乐
current: number;

this.current=cc.audioEngine.play(this.tanren1,false,1);//播放
cc.audioEngine.pause(this.current);//结束
cc.audioEngine.stop(this.current);//结束

3.访问节点和组件

还有几个高级的

var node = this.node;//当前所在节点

var label = this.getComponent(cc.Label);//当前所在节点的其他组件
//如果在节点上找不到你要的组件,getComponent 将返回 null,
var label = this.getComponent(cc.Label);
    if (label) {
        label.string = "Hello";
    }
    else {
        cc.error("Something wrong?");
    }//当一个预防措施
var rotate = this.getComponent("SinRotate");//获取其他脚本

this.backNode = cc.find("Canvas/Menu/Back");//全局查找

4.生命周期

在这里插入图片描述


5.数据储存cc.sys.localStorage

//cc.sys.localStorage API
cc.sys.localStorage.setItem(key,value);     //key 为字符串类型,value为数值或字符串
cc.sys.localStorage.getItem(key);           //返回值为数值或者字符串。若数据不存在,则返回null
cc.sys.localStorage.removeItem(key);        //根据键值删值
cc.sys.localStorage.clear();                //清空所有通过cc.sys.localStorage保存的数据

6.图片的轮换

bg:cc.Node;
bg1:cc.Node;
this.bg= this.node.getChildByName("bg");
this.bg1= this.node.getChildByName("bg1"); 

this.bg.y-=5;
this.bg1.y-=5;
 if(this.bg1.y<=-1080)
 {
     this.bg1.setPosition(cc.v2(0,1080));
 }
 if(this.bg.y<=-1080)
 {
    
     this.bg.setPosition(cc.v2(0,1080));
 }
 //还有设置bg的y=1080;

总结

就到着了,就是主要看官方文档,然后不断的多做几个游戏,功夫就自然水到渠成。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

joyyi9

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值