当前位置:网站首页>Wechat games (3)
Wechat games (3)
2022-06-22 07:25:00 【qq_ forty-five million nine hundred and sixty-nine thousand fiv】
One 、 Task content
The main content of this time is the script of the main body of the game , As the key part .
Two 、 Specific contents and key codes
1. initial
onLoad() {
this.success = false;
// Initial score
this.scoreNum = 0;
},
start () {
let countDownLabel = cc.find("Canvas/bg_sprite/count_down").getComponent(cc.Label);
countDownLabel.string = this.time + "s";
this.schedule(function () {
this.time --;
countDownLabel.string = this.time + "s";
if (this.time == 0) {
cc.log(" Game over !");
// Get pop-up node
let resultNode = cc.find("Canvas/result");
// obtain title and content Two nodes
let titleNode = resultNode.getChildByName("title");
let contentNode = resultNode.getChildByName("content");
// Show the score
titleNode.getComponent(cc.Label).string = " The final score " + this.scoreNum;
// Get components
let contentLabel = contentNode.getComponent(cc.Label);
switch (true) {
case this.scoreNum <= 3:
contentLabel.string = " Bull set bronze ";
break;
case this.scoreNum < 6:
contentLabel.string = " A bull trap expert ";
break;
case this.scoreNum >= 6:
contentLabel.string = " The king of cattle ";
break;
}
resultNode.active = true;
cc.director.pause();
}
},1);
},
2. Capture button click events
Set rope
clickCapture:function (event,customEventDate) {
this.rope_node.active = true;
// Set the order of the rope at the current parent node
this.rope_node.setSiblingIndex(100);
// Set the starting position of the rope
this.rope_node.y = -480;
// Move up
const up = cc.moveTo(0.5,this.rope_node.x,60);
Set the judgment result
let result = cc.callFunc(function () {
// Get the current cow's x spot
let currentX = this.cow_ins.x;
if (currentX > -100 && currentX < 100){
cc.log(" Capture success !");
// remove
let bgNode = this.node.getChildByName("bg_sprite");
bgNode.removeChild(this.cow_ins);
// Get the type of cow
let ropeType = this.cow_ins.getComponent("cow").randomType +1;
this.rope_node.getComponent(cc.Sprite).spriteFrame = this.rope_imgs[ropeType];
// Generate a new cow node
this.cow_ins = cc.instantiate(this.cow_prefab);
this.cow_ins.y = 0;
bgNode.addChild(this.cow_ins);
//
this.success = true;
// fraction +1
this.scoreNum ++;
} else {
cc.log(" Capture failed !")
}
},this);
Determine whether the capture is successful
let finish = cc.callFunc(function () {
this.rope_node.getComponent(cc.Sprite).spriteFrame = this.rope_imgs[0];
// Determine whether the capture is successful
if (this.success == true) {
let scoreLabel = cc.find("Canvas/bg_sprite/score").getComponent(cc.Label);
scoreLabel.string = "Score:" + this.scoreNum;
this.success = false ;
}
},this)
close button , Keep playing
closeBtn() {
cc.log(" Keep playing ");
cc.director.resume();
cc.director.loadScene("game");
}
3、 ... and 、 summary
The game script is basically completed , Combined with the rest of the work, the game will be basically completed .
边栏推荐
- Developing a contract application with low code
- Detr3d model source code Guide & mmdetection3d construction process
- How to batch copy babies by sales volume in Taoying
- 2 lines of text on the right of the left Avatar
- Wechat applet service provider sub merchant payment order interface
- Real MySQL interview question (18) -- practical operation analysis
- Get through version 4.3 mind map
- Open version - account information synchronization and unification
- Canoe learning notes (6) diagram of logging block data recording module
- Crmeb open source version, a free mall worth trying
猜你喜欢

Canoe learning notes (2) diagram of trace window introduction

Use of sessionstorage and localstorage

5G NR PWS系统
The solution of word document being locked and unable to edit

Up sampling and down sampling (notes, for personal use)

How to upload Taobao tmall products with one click

True MySQL interview question (19) -- Tiktok -- select the list of users who have logged in for two consecutive days every month

33歲程序員的年中總結

Real MySQL interview question (18) -- practical operation analysis

Kuangshi brain++ Tianyuan platform megstudio
随机推荐
Propeller framework v2.3 releases high reusable operator library Phi: Restructure development paradigm, reduce cost and increase efficiency
A simple examination system based on C language
Access to control objects in JS
Canoe learning notes (3) graphic window introduction diagram
Flutter uses the for loop
Reasons and solutions for Taobao's baby's prompt "sales attribute is required and parameter format is wrong"
Canoe learning notes (2) diagram of trace window introduction
MySQL面试真题(十八)——经营分析实战
[usecols parameter of pd.read\u excel ((), list error reason]
The solution of word document being locked and unable to edit
Canoe learning notes (1) illustration of new project and channel configuration steps
Typescript & explain in, keyof, extensions, index signature, record and typeof in detail (updated from time to time)
selenium防爬和模拟手机浏览器
Protection of RT thread critical section
What are the ways for Taobao merchants to put their babies on the shelves in batches
汇编学习《汇编语言(第三版)》王爽著第四章学习
Crmeb mall order shipping function
RFID warehouse management system solution implementation visualization process
Image interpolation (nearest neighbor, bilinear)
About pointer (notes, for personal use)