实例化小球
InitBulletNumArr(s: number, node: Node) {
for (let i = 0; i < s; i++) {
let p = instantiate(node)
p.setParent(this.node)
p.active = false
this.LineBulletArr.push(p)
}
this.LineBullet.active = false
}
update函数中的CanDraw代表可以画线
update(deltaTime: number) {
if (this.Pao1.getComponent(Pao1).isScFlag == false && this.BulletArr.getComponent(BulletArr).count == 0) {
this.CanDraw = true
}
else if (this.Pao1.getComponent(Pao1).isScFlag == true && this.BulletArr.getComponent(BulletArr).count > 0) {
this.CanDraw = false
}
if (this.CanDraw) {
let angle = this.node.eulerAngles.z * 2 / 360 * Math.PI;
//计算基于Y轴的方向向量
let dir = v2(Math.cos(angle), Math.sin(angle));
//方向向量进行单位化
dir.normalize()
for (let i = 0; i < this.BulletNum; i++) {
if (this.LineBulletArr[i].getWorldPosition().x < -18) {
let t = this.LineBulletArr[i].getWorldPosition
this.LineBulletArr[i].setPosition(i * 50 * dir.y, i * 50 * dir.x, 0)
this.LineBulletArr[i].setWorldPosition(-(this.LineBulletArr[i].getWorldPosition().x + 20), this.LineBulletArr[i].getWorldPosition().y, 0)
if (this.LineBulletArr[i].active == false) {
this.LineBulletArr[i].active = true
}
}
else if (this.LineBulletArr[i].getWorldPosition().x > 700) {
this.LineBulletArr[i].setPosition(i * 50 * dir.y, i * 50 * dir.x, 0)
this.LineBulletArr[i].setWorldPosition(1424 - this.LineBulletArr[i].getWorldPosition().x, this.LineBulletArr[i].getWorldPosition().y, 0)
if (this.LineBulletArr[i].active == false) {
this.LineBulletArr[i].active = true
}
}
else {
this.LineBulletArr[i].setPosition(i * 50 * dir.y, i * 50 * dir.x, 0)
if (this.LineBulletArr[i].active == false) {
this.LineBulletArr[i].active = true
}
}
}
}
if (!this.CanDraw) {
for (let i = 0; i < this.BulletNum; i++) {
if (this.LineBulletArr[i].active != false) {
this.LineBulletArr[i].active = false
}
}
}
}