飞机大战需要背景图,飞机,子弹,敌机
下面写的是css代码实现子弹的运动
for (var i = 0; i < this.objB.arr.length; i++) {
var newArr = this.objB.arr[i].split(‘|‘);//[id|top|left]
var eleB = document.getElementById(newArr[0]);
newArr[1] = parseInt(newArr[1]) - 1; //将上一个的newArr1减1并赋值
// console.log(newArr[1]);
eleB.style.top = newArr[1] + ‘px‘;
this.objB.arr[i] = newArr[0] + ‘|‘ + newArr[1] + ‘|‘ + newArr[2];
if (newArr[1] < 0) {
this.objB.arr.splice(i, 1);
var delEle = document.getElementById(newArr[0]);
delEle.parentNode.removeChild(delEle);
}
console.log(newArr);
}
整个飞机大战,我认为的最关键的部分,就是让子弹运动起来,和敌机一样
原文地址:https://www.cnblogs.com/1179929172-zh/p/11444556.html
时间: 2024-10-09 00:02:02