一.注册小程序

要开发小程序自然要申请注册一个小程序,我们先进入微信公众平台注册账号(若有账号则直接登录)。

因为微信公众号同时管理着订阅号,公众号以及小程序等多种账号,所以这里要选择小程序账号类型;记住,不同公众号服务之间账号不通用,所以使用注册的邮箱不能被其它公众号服务或者自己微信绑定过。

注册完成后登陆,就可以创建 自己的小程序了,在填写完成创建小程序后,我们可以得到一个唯一小程序AppID。

二.安装开发工具

安装cocosDashborad 里面集成了很多cocos不同版本.

Vs主要用于编写js,ts代码,更加方便

IDea主要服务器使用,这里服务器语言用的是java.数据库redis

三.创建项目

这个游戏创建了两个模式,一个是选择不同模式的代码,根据传入的值不同来控制显示问题.一个是根据不同的模式,来加载不同的游戏场景.

choice(event, data: number) {let self = this.node;this.gameType.forEach(num => {var str = "item" + num;if (num == data) {self.getChildByName("jsgroup").getChildByName(str).getChildByName("peach").active = true;} else {self.getChildByName("jsgroup").getChildByName(str).getChildByName("peach").active = false;}})GLB.type = data;}moveOut(evt: cc.Node.EventType) {console.log("切换场景" + evt)if (GLB.type == 2) {cc.director.loadScene('gameMoving')} else {cc.director.loadScene('game')}}

下面是其中一个游戏模式的场景,由人物,分数条,加背景拼凑.主要有人物控制脚本,水果控制脚本,以及分数控制脚本.

水果控制脚本.

const { ccclass, property } = cc._decorator;@ccclass
export default class ballScript extends cc.Component {@propertyballHeight: number = 40;parentHeight: number = 0;parentWidth: number = 0;@propertyspeed: number = 2;//默认方向,从左往右@propertyballDirection: boolean = false;//控制转向controlDirectionY: boolean = true;// controlDirectionX: boolean = true;gameType: number = 1;id: number = 0;playerNodeY: number = 0;ballColor: cc.Color[] = [cc.Color.BLACK, cc.Color.BLUE, cc.Color.CYAN, cc.Color.GREEN,cc.Color.ORANGE, cc.Color.RED, cc.Color.YELLOW, cc.Color.MAGENTA, cc.Color.TRANSPARENT, cc.Color.WHITE]// LIFE-CYCLE CALLBACKS:// onLoad () {}start() {//设置初始高度this.ballHeight = this.node.y;//开启物理碰撞var manager = cc.director.getCollisionManager();manager.enabled = true;if (this.gameType == 2) {} else {this.speed = 1 + Math.floor(Math.random() * 2);}this.parentHeight = this.node.getParent().height - this.node.height;this.parentWidth = this.node.getParent().width / 2;}onCollisionEnter(other: cc.Node, self: cc.Node) {// console.log('on collision enter' + self.name);// console.log('on collision other' + other.name);if (other.name.startsWith("land")) {this.controlDirectionY = false;}}update(dt) {if (this.gameType == 2) {this.node.x -= this.speed;if (this.node.x <= -this.parentWidth) {this.node.active = false;}} else {if (this.ballDirection) {this.node.x -= this.speed;if (this.node.x <= -this.parentWidth) {this.ballDirection = !this.ballDirection;}} else {this.node.x += this.speed;if (this.node.x >= this.parentWidth) {this.ballDirection = !this.ballDirection;}}if (this.controlDirectionY) {this.node.y -= this.speed;} else {if (this.node.y >= this.ballHeight || this.node.y >= this.parentHeight) {this.controlDirectionY = true;}this.node.y += this.speed;}}}
}

人物控制脚本

import { GLB } from "./config/GLBConfig";
import gameScript from "./game/gameMovingScript";
import { WS } from "./socket/Socket";const { ccclass, property } = cc._decorator;@ccclass
export default class PlayerScriptClass extends cc.Component {@property(cc.AudioClip)diedAudio: cc.AudioClip = null;@property(cc.AudioClip)diedAfterAudio: cc.AudioClip = null;// LIFE-CYCLE CALLBACKS:onLoad() {//开启物理碰撞var manager = cc.director.getCollisionManager();manager.enabled = true;cc.director.preloadScene('ready')//debug 绘制//  manager.enabledDebugDraw = true;//显示碰撞盒子//  manager.enabledDrawBoundingBox = true;}start() {}onCollisionEnter(other, self: cc.Node) {let gameType = GLB.type;let backGreound: gameScript;if (gameType == 2) {backGreound = this.node.getParent().getChildByName("background").getComponent(gameScript)} else {backGreound = this.node.getParent().getComponent(gameScript)}if (backGreound != null) {let score: number = GLB.score;if (backGreound.totalScore >= score) {GLB.score = backGreound.totalScore;WS.sendMsg(GLB.PUTSCORE, GLB.playerId + ":" + backGreound.totalScore);}console.log("当前分数: " + backGreound.totalScore)}//角色死亡self.getComponent(dragonBones.ArmatureDisplay).playAnimation("died", 0);cc.audioEngine.stopAll();cc.audioEngine.play(this.diedAudio, false, 0.5);let nowAudio = this.diedAfterAudio;this.scheduleOnce(() => {console.log("------播放音乐---")cc.audioEngine.play(nowAudio, false, 0.5)cc.director.loadScene('ready')}, 0.2);}// update (dt) {}
}

欢迎大家多多体验,提出问题,大家共同进步.多多交流

从零开始微信小游戏(cocos creator)相关推荐

  1. cocos creator开发微信小游戏(五)贪吃蛇大作战

    目录 小游戏介绍 小游戏cocos creator场景图 小游戏部分JS代码 开发中碰到的问题 工程及说明 小游戏介绍 贪吃蛇小游戏:贪吃蛇试玩(首次加载比较慢),类似贪吃蛇大作战的小游戏.当玩家的蛇 ...

  2. 麒麟子Cocos Creator 3D研究笔记零:从零开始入门并发布微信小游戏

    编辑器状态截图 不要在意名字,我临时借用的小游戏APPID 一.前言 Cocos Creator,我回来了. 2016年6月,大家都觉得Cocos Creator 2D不够成熟的时候,我就开始商用了. ...

  3. Cocos Creator发布微信小游戏包内体积过大问题

    1.初识 设置微信开发工具和js编辑器 3.5.2 :Cocos Creator perferences 2.Cocos Creator发布微信小游戏包内体积过大问题 2.1 已不可取:搭建本机服务器 ...

  4. 微信小游戏实战--cocos creator实现wordle游戏(六)

    就wordle游戏本身而言它已经完成了,但我并不打算就到此为止."麻雀虽小五脏俱全",从"完整"的角度来看,它还缺少一些"必不可少"的功能: ...

  5. cocos creator 微信小游戏接口

    cocos creator 微信小游戏接口 /** @Description:微信小游戏* @version: * @Author: lvpeijun* @Date: 2019-12-02 10:43 ...

  6. Cocos Creator Erro 4916,Failed to load scene的问题找到了!---cocos creator打包微信小游戏的坑

    首先我们来回顾一下问题 当我在用cocos微信小游戏开发的时候,发现你加上开放数据域居然不能超过8M ,wtf? 于是我把自己打包后的res文件夹放在服务器上并且删了本地的res文件.结果问题来了 这 ...

  7. 微信小游戏排行榜:Cocos Creator

    上一篇文章介绍了主域和子域的概念,微信小游戏:主域子域,这一篇介绍一下怎样在微信小游戏中制作好友排行榜 创建工程 由于开放数据域是一个封闭.独立的 JavaScript 作用域,所以开发者需要创建两个 ...

  8. 微信小游戏实战--cocos creator实现wordle游戏(一)

    前言 前段时间赋闲在家,整理电脑上的资料时才发现从业这么多年都是在给公司打工,没为自己写过点什么,所以决定为自己写一个完整的"产品".同时,为了检验一下自己的学习能力,选择了从未接 ...

  9. 微信小游戏实战--cocos creator实现wordle游戏(五)

    到目前为止我们已经实现了整个游戏的界面以及"空格"和键盘按钮的动画,接下来完成游戏的基础玩法流程. 完整代码 一.初始化游戏 由于在游戏中"空格"的背景和Lab ...

  10. Cocos Creator之微信小游戏的游戏圈

    Cocos Creator之微信小游戏的游戏圈 1.官方文档游戏圈使用指南 · 小游戏: 2.需要将游戏圈放到指定地方(比如下图,坐标为x:160,y:850,因为游戏圈图标的锚点在左上角,所在层的锚 ...

最新文章

  1. 异步错误处理 -- 时机
  2. 浅谈React虚拟DOM
  3. 11.13 ethtool:查询网卡参数
  4. java studentmanager_StudentManager.java
  5. shell if condition
  6. .NET连接SQL Server
  7. PyTorch中的梯度微分机制
  8. CS106 错误拒绝访问
  9. matlab构建公式模块,第五章 matlabsimlink下数学模型的建立.ppt
  10. 前端程序员 学习书籍推荐
  11. Excel数值函数(4):对指定条件的单元格求和
  12. 投标书如何写?(转)
  13. AI行为识别:安防主动预警
  14. 微信文章抓取:微信公众号文章抓取常识之临时链接、永久链接
  15. css - 实现镜头拉近效果
  16. 腾讯文档服务器,腾讯内部培训资料服务器硬件介绍-20210712081429.ppt-原创力文档...
  17. react组件中箭头函数的使用
  18. 极速pdf文件打印时此计算机未连接到网络,PDF文件不能打印的五种解决方案
  19. idea的language level含义和module的language level自动跳到5
  20. “仁、义、礼、智、信、忠、孝、节、勇、和”

热门文章

  1. 【转】深入浅出的讲解傅里叶变换(真正的通俗易懂)
  2. DVR硬盘录像机技术
  3. centos设置ftp默认端口
  4. pcm5102a解码芯片音质评测_音乐更重要,iQOO Pro配备独立解码芯片,Hi-Fi音质更懂你...
  5. 共识机制是什么意思?
  6. 聚合支付系统设计(一)
  7. ubuntu全版本安装 NVIDIA显卡驱动、以及重装、卸载
  8. 2020求职必读!疫情后有哪些风口行业和公司?
  9. 数字地与模拟地解释及PBC底线布局
  10. easypoi excel模板导出pdf