当前位置:网站首页>Spin animation of Cocos performance optimization
Spin animation of Cocos performance optimization
2022-07-07 15:39:00 【Vegetable chicken on the road】
Recently, I was working on a tower defense project , How to put it? , Battery , Bullet attack effect plus hit effect, etc. Let's take a look at the code dc Stable at 200+, This is just the core game logic , If you add ui That's got it. , Ordinary mobile phones hang up directly after a few minutes , Then I think I can only optimize it first , At this time, I thought I had seen a sliding layer optimization code before , So I thought about taking his thoughts directly to use according to the gourd painting ladle , After practice, it is found that it is indeed feasible , Don't sigh big guy or big guy .
Let's take a look at what happened before optimization dc, There are only two kinds of guns 120 了 :
Look now ,n Kind of cannon plus bullet effect plus hit effect :
Let's talk about ideas directly , First in the main scene , Hang a node , Something specially used for rendering layers , For example, the cannon in this project , I'll screw it out and make a node for storage , And hang up the script turretRender.ts, It mainly does two things ,
1. Clone one that needs to be used spine Node and add it to this render node
2. When not in use destroy fall 
Code :
addRenderNodeToRoot(type,name:string, node:cc.Node){
let baseNode:cc.Node = this._turretRoot;
let parentNode:cc.Node = baseNode.getChildByName(name);
if(parentNode){
parentNode.addChild(node);
return;
}
parentNode = new cc.Node;
parentNode.name = name;
baseNode.addChild(parentNode);
parentNode.addChild(node);
}
removeSpineNodeFromRoot(node:cc.Node){
if(node){
node.destroy();
}
}
After we load spine Copy the original node , This copied node will exist as the node we need to render later and add it to the above creation turrtRender in , The code is as follows :
load spine Animation nodes , Give him a callback after loading :
loadSpineImg(callback: Function) {
if (this.bulletSpine) {
this.bulletSpine.skeletonData = null;
}
this.loadSpine("spine/turret/" + this.bulletData.type + "/bullet/" + this.bulletData.name, sp.SkeletonData, (error, sp: sp.SkeletonData) => {
if (error) {
cc.warn(error);
return;
}
this.bulletSpine.skeletonData = sp;
callback && callback();
})
}
Loading complete spine Handle cloning logic in the callback after the node , What we need to pay attention to here is , We need to hide the original node , Shows the cloned nodes , Position set , Later, the operations of the original interface are all changed to the cloned node operations , It should be noted that , Remember to judge whether the cloned node exists , Also, ensure that the location is updated in real time
this.loadSpineImg(() => {
if (this.cloneBulletSpine) {
turretRender.inst.removeSpineNodeFromRoot(this.cloneBulletSpine);
this.cloneBulletSpine = null;
}
this.cloneBulletSpine = cc.instantiate(this.bulletSpine.node);
this.cloneBulletSpine.removeAllChildren();
this.cloneBulletSpine.active = true;
this.bulletSpine.node.active = false;
let name: string = this.bulletData.type+"_paodan";
turretRender.inst.addRenderNodeToRoot(RenderNodeType.renderBulletSpine,name, this.cloneBulletSpine);
let wPos = this.bulletSpine.node.parent.convertToWorldSpaceAR(this.bulletSpine.node.getPosition());
let lPos = this.cloneBulletSpine.parent.convertToNodeSpaceAR(wPos);
this.cloneBulletSpine.setPosition(lPos);
// Callback
if (this.bulletData.Spine == 1) {
this.cloneBulletSpine.getComponent(sp.Skeleton).setAnimation(0, this.bulletData.animationName, this.bulletData.loop == "1");
this.isMoment = false;
} else {
this.cloneBulletSpine.getComponent(sp.Skeleton).clearTracks();
this.playAni();
}
});
Monitor the location to update the code in real time , Otherwise, the position will shift :
start() {
this.node.on(cc.Node.EventType.POSITION_CHANGED, this.updatePos, this);
this.bulletSpine.node.on(cc.Node.EventType.ROTATION_CHANGED, this.updatePos, this);
}
updatePos() {
if (this.bulletSpine && this.cloneBulletSpine) {
let wPos = this.bulletSpine.node.parent.convertToWorldSpaceAR(this.bulletSpine.node.getPosition());
let lPos = this.cloneBulletSpine.parent.convertToNodeSpaceAR(wPos);
this.cloneBulletSpine.setPosition(lPos);
this.cloneBulletSpine.angle = this.node.angle;
}
}
In fact, the main purpose of doing this is to jointly approve , If you add it one by one ,spine Batch operation will be interrupted in some places , It leads to the failure of the approval ,dc It will be quite high .
---------------------------------------------------------- Split line ----------------------------------------------------------------------
Two easy-to-use plug-ins are recommended :
1. see dc The drawing situation of :spector.js, How to use Baidu by yourself , Can detect after optimization dc Whether the drawing is correct
Pictured , Click on the blue part every time dc What are you drawing :
2.ccc-devtools plug-in unit , You can see the whole cocos Hierarchical structure , See which node a node is under , Here you can monitor cloned spine Whether the node is added turretRender Under the node 
边栏推荐
- Unity's ASE realizes cartoon flame
- Wechat applet 01
- 【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)
- [Data Mining] Visual Pattern Mining: Hog Feature + cosinus Similarity / K - means Clustering
- Ctfshow, information collection: web4
- Detailed explanation of Cocos creator 2.4.0 rendering process
- 【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
- [deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
- What is data leakage
- leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
猜你喜欢

Getting started with webgl (4)

2. 堆排序『较难理解的排序』

【数据挖掘】视觉模式挖掘:Hog特征+余弦相似度/k-means聚类

众昂矿业:萤石继续引领新能源市场增长

【数字IC验证快速入门】25、SystemVerilog项目实践之AHB-SRAMC(5)(AHB 重点回顾,要点提炼)

【搞船日记】【Shapr3D的STL格式转Gcode】
![[quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)](/img/cf/45775b712f60869186a25d3657ee1b.png)
[quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)

Ctfshow, information collection: web14
Implementation of crawling web pages and saving them to MySQL using the scrapy framework

全日制研究生和非全日制研究生的区别!
随机推荐
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
Mathematical modeling -- what is mathematical modeling
MySQL bit type resolution
[quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)
2022 all open source enterprise card issuing network repair short website and other bugs_ 2022 enterprise level multi merchant card issuing platform source code
[quickstart to Digital IC Validation] 20. Basic syntax for system verilog Learning 7 (Coverage Driven... Including practical exercises)
Stm32f103c8t6 PWM drive steering gear (sg90)
Write sequence frame animation with shader
Ctfshow, information collection: web2
[deep learning] image hyperspectral experiment: srcnn/fsrcnn
[quick start of Digital IC Verification] 22. Ahb-sramc of SystemVerilog project practice (2) (Introduction to AMBA bus)
How to understand that binary complement represents negative numbers
"Baidu Cup" CTF competition 2017 February, web:include
Wechat applet 01
Actually changed from 408 to self proposition! 211 North China Electric Power University (Beijing)
Starting from 1.5, build a microservice framework link tracking traceid
什麼是數據泄露
摘抄的只言片语
Win10 or win11 taskbar, automatically hidden and transparent
Share the technical details of super signature system construction