当前位置:网站首页>cocos3——8. Implementation Guide for beginners
cocos3——8. Implementation Guide for beginners
2022-07-07 03:10:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
1. use ClippingNode Clipping range
Write crop interface :
function createClipNode(node, stencil, inverted) {
var clip_node = new cc.ClippingNode();
// Set the template node ( Is the area to be cropped )
clip_node.stencil = stencil;
// Add nodes to be trimmed ( Display content )
clip_node.addChild(node);
if (inverted != undefined) {
// Set reverse ( Because we need to keep the content outside the template area , Cut out the content in the area )
clip_node.setInverted(inverted);
}
clip_node._stencil = stencil;
return clip_node;
}Create a clipping node in the guide layer :
// create clip node
var mask = cc.LayerColor.create(cc.color(0, 0, 0, ui.mask_a), ui.screen_width, ui.screen_height);
var stencil = cc.LayerColor.create(cc.color.GREEN, 100, 100);
stencil.ignoreAnchorPointForPosition(false);
this.clip_node = createClipNode(mask, stencil, true);
this.addChild(this.clip_node, ui.mask_z);Here is the creation of a full screen black mask layer , Then cut it off stencil Region . To change the area , We just need to change stencil The position and size of .
Then write the trimmed function in the boot layer :
node.clipNode = function (ref) {
this.clip_ref = ref;
var stencil = this.clip_node.stencil;
if (ref) {
stencil.setAnchorPoint(ref.getAnchorPoint());
stencil.setContentSize(ref.getContentSize());
stencil.setPosition(ref.getParent().convertToWorldSpace(ref.getPosition()));
} else {
// set out of screen
stencil.setPosition(cc.p(10000, 10000));
}
}This function uses the reference node passed in ref The anchor point 、 size 、 Position to set the properties of the template , In this way, it can be trimmed according to the reference node .
2. Simple process of guidance
For simple boot implementation , It starts at the place where the guidance starts 、 Where the guidance ends .
And when to start 、 When will it come to an end? , Suppose the quantity is small and starts 、 If the ending conditions are special ,
You can find relevant places to start and end the guidance .
The assumptions are large and the conditions are relatively general ( example button The end of the incident 、 The sliding event ends ), Be able to condition Abstract words . Then configure .
Here is a simple way , First prepare the interface to guide the start and end .
First get the last boot steps from the file stream , Used here local storage:
// local storage
var storage = {
ls: cc.sys.localStorage,
};
storage.set = function (key, value) {
this.ls.setItem(key, value);
}
storage.get = function (key) {
var value = this.ls.getItem(key);
if (value != '') {
return value;
}
}
storage.remove = function (key) {
this.ls.removeItem(key);
}
// global interface
var guide = {
node: node,
};
// arrow: // 0 down, 1 right, 2 up, 3 left
guide.steps = [
// 0
{
name: 'btn_right',
str: ' Please hold button, Control , Throw the sandbag into the red area .', arrow: 1, }, // ...];// Get the number of steps completed in the last boot guide.cur_step = storage.get('guide') || 0;Then prepare the interface for starting and ending boot :
guide.start = function (step) {
if (step == this.cur_step) {
console.log('guide start:', step, ',', this.cur_step);
this.started = true;
this._show(true);
var info = this.steps[this.cur_step];
this.node.updateData(info);
}
}
guide.end = function (step) {
if (!this.started) {
return;
}
this.started = false;
if (step == undefined) {
step = this.cur_step;
}
if (step == this.cur_step) {
console.log('guide end:', step, ',', this.cur_step);
storage.set('guide', ++this.cur_step);
this._show(false);
}
}
guide._show = function (show) {
if (show) {
if (!this.node.getParent()) {
this.node.init();
ui.scene.addChild(this.node);
}
}
this.node.visible = show;
}above guide Inside node It is the root node of the boot interface . Boot start guide.start When , Infer that the number of steps is the current step . Just guide the current step , Configured from above steps Get the text content to be guided .
And the name of the reference node ( The reference node will be hung to guide.start The current interface being called node Under the object )、 And arrows ( written words 、 I won't say more about the arrow display ). Then update the crop region 、 According to the text 、 Arrow, etc . Add the current number of steps at the end of the boot .
When actually designing each guide , For example, in Chapter i When you walk , Go to the beginning and call guide.start(i), When the guidance is over guide.end(i) You can .
Here is a simple single line guide , For simple
Novice guidance is enough .
Copyright notice : This article is the original article of the blogger . Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116793.html Link to the original text :https://javaforall.cn
边栏推荐
- Summary of research status of inertial navigation calibration at home and abroad (abridged version)
- Code debugging core step memory
- Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (time synchronization part)
- 左程云 递归+动态规划
- Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (initial assignment part)
- 杰理之在非蓝牙模式下,手机连接蓝牙不要跳回蓝牙模式处理方法【篇】
- 从 1.5 开始搭建一个微服务框架——日志追踪 traceId
- 杰理之电话本获取【篇】
- 2022 spring recruitment begins, and a collection of 10000 word interview questions will help you
- 【安全的办公和生产力应用程序】上海道宁为您提供ONLYOFFICE下载、试用、教程
猜你喜欢
MySQL提升大量数据查询效率的优化神器
![[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication](/img/09/b9d50f7a10e6898ac4088ee005d00b.png)
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
Django database (SQLite) basic introductory tutorial

tensorboard的使用

Don't you know the relationship between JSP and servlet?

How to write test cases for test coupons?

Household appliance industry under the "retail is king": what is the industry consensus?

A complete tutorial for getting started with redis: AOF persistence

尚硅谷JVM-第一章 类加载子系统

Redis入門完整教程:問題定比特與優化
随机推荐
Starting from 1.5, build a micro Service Framework -- log tracking traceid
The whole process of knowledge map construction
MySQL is an optimization artifact to improve the efficiency of massive data query
C language string sorting
cocos3——8.实现初学者指南
Babbitt | metauniverse daily must read: is IP authorization the way to break the circle of NFT? What are the difficulties? How should holder choose the cooperation platform
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (time synchronization part)
房费制——登录优化
Unity uses maskablegraphic to draw a line with an arrow
杰理之播内置 flash 提示音控制播放暂停【篇】
Kubernetes source code analysis (II) -- resource
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
Analysis of USB network card sending and receiving data
How does C language (string) delete a specified character in a string?
Don't you know the relationship between JSP and servlet?
杰理之开启经典蓝牙 HID 手机的显示图标为键盘设置【篇】
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
杰理之发射端在接收端关机之后假死机【篇】
Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
Uniapp adaptation problem