当前位置:网站首页>Starting from scratch (IV) enemy aircraft flying out of the border disappear automatically
Starting from scratch (IV) enemy aircraft flying out of the border disappear automatically
2022-06-11 06:46:00 【Dare you look at the avatar for three seconds?】
Problems encountered

As shown in the figure , In order to realize the random increase of enemy aircraft and the first random flight of players on the stage, do you know , When checking the console, I found , When the enemy plane flies over the stage, it will not disappear automatically , So that the program will take up too much memory space , The situation is somewhat similar to the memory leak that is not released in time when dynamic memory allocation is implemented , So when the computer slows down at visible speed , How to make the enemy aircraft disappear automatically becomes more and more difficult
Before that, first understand a few concepts
Every enemy plane is loaded by us html One of the nodes in , Or labels
understand dom node
document object model---- Document object model
Our need is , After the enemy aircraft flies over the stage, the corresponding... Will be deleted automatically html node , Before deleting, we need to find a way to get the corresponding node of the aircraft flying out of the stage
dom The attribute acquisition problem of the node
Get the properties of all nodes ( Height or something ) Not directly in js Inside point , You can't get , This also applies jq Why
But the input field can be clicked directly value
Specific code :
// When you leave the stage, remember to remove dom node
setInterval(function(){
for(i=0;i<enemy.length;i++){
var tmp_enemy=parseFloat($(enemy[i]).css("top"));
var tmp_stage=$(stage).height();
// console.log(tmp_enemy);
// console.log(typeof($(tmp_stage).height()));
if(tmp_enemy>tmp_stage){
$(enemy[i]).remove();
console.log(" Removed successfully ")
}
}
},500)
边栏推荐
- About parseint()
- Exchange two values without introducing the third variable
- 3.1 测试函数的命名规则
- Using Metasploit Trojan horse for remote control
- []==![]
- On cursor in MySQL
- Fix the problem that the right mouse button does not have a vscode shortcut
- 538.把二叉搜索树转换成累加树
- Metasploitabile2 target learning
- Learn C language well from keywords
猜你喜欢

【Matlab WSN通信】A_Star改进LEACH多跳传输协议【含源码 487期】

Examinelistactivity of Shandong University project training

break,continue有什么区别和用法?

Sentinel annotation support - @sentinelresource usage details

Redux learning (I) -- the process of using Redux

Sohu employees encounter wage subsidy fraud. What is the difference between black property and gray property and how to trace the source?

Redux learning (II) -- encapsulating the connect function

563. 二叉树的坡度
![JS implementation of Hill sort of graphic insertion sort [with source code]](/img/5a/b89fd5a0ebbc7ca17cc3e1fcb37c8f.jpg)
JS implementation of Hill sort of graphic insertion sort [with source code]

572. 另一个树的子树
随机推荐
Make a small game with R language and only basic package
Jenkins user rights management
572. subtree of another tree
关于 QtCreator的设计器QtDesigner完全无法正常拽托控件 的解决方法
538. convert binary search tree to cumulative tree
022-Redis数据库0基础入门
JVM from getting started to abandoning 1: memory model
A promise with bare hands
ijkPlayer中的错误码
100. same tree
The nearest common ancestor of 235 binary search tree
Use of qscriptengine class
Count the time-consuming duration of an operation (function)
Dynamic import
About the principle and code implementation of Siou (review IOU, giou, Diou, CIO)
Alias the path with the help of craco
617. merge binary tree
Mediaextractor source code analysis of multimedia framework analysis (1)
Won't virtual DOM be available in 2022? Introduction to virtual Dom and complete implementation of diff and patch
数学方法论的含义和研究意义