激光没射到敌人是全屏的,射到敌人了就只到敌人距离的长度,我这有个问题就是碰撞盒子的执行onCollisionEnter是再update后面,我碰撞后设置长度,第一帧是全屏长度就会闪一下
有没有做过类似了,科普下怎么弄的激光?
import { BeanType } from “…/…/data/Enum”;
import { FightActor } from “…/role/FightActor”;
import PlaneNode from “…/role/PlaneNode”;
import { Bullet } from “./Bullet”;
import BulletNode from “./BulletNode”;
import LaserBullet from “./LaserBullet”;
const { ccclass, property } = cc._decorator;
@ccclass
/**激光碰撞 */
export default class LaserBulletNode extends BulletNode {
protected cur_time: number = 0;
public cur_hit_node: cc.Node = null;
protected mediator: LaserBullet = null;
private count: number = 0;
/**碰撞 */
public onCollisionEnter(other: cc.Collider, self: cc.Collider): void {
let actor: FightActor = other.getComponent(PlaneNode).actor as FightActor;
if (!actor || actor.camp === this.mediator.camp) {
return;
}
if (!actor || actor.node.y > cc.Canvas.instance.node.height / 2) return;
this.addHideNode(other);
}
// onCollisionStay(other: cc.Collider, self: cc.Collider): void {
// let actor: FightActor = other.getComponent(PlaneNode).actor as FightActor;
// if (!actor || actor.camp === this.mediator.camp) {
// return;
// }
// if (!actor || actor.node.y > cc.Canvas.instance.node.height / 2) return;
// if (other.node = this.cur_hit_node) return;
// this.addHideNode(other);
// }
public onCollisionExit(other: cc.Collider, self: cc.Collider): void {
// this.removeHitBox(other);
if (this.cur_hit_node === other.node) {
this.cur_hit_node = null;
this.cur_time = 0;
}
}
lateUpdate(): void {
this.count += 1;
console.log("lateUpdate:" + this.count);
this.updateCanvasHeight();
}
update(dt: number): void {
if (!this.cur_hit_node) {
return;
}
if (this.cur_time == 0) {
// console.log("kill")
this.mediator.HitCurNode(this.cur_hit_node);
}
this.cur_time += dt;
if (this.cur_time > .2) {
this.mediator.HitCurNode(this.cur_hit_node);
this.cur_time -= .2;
}
}
protected addHideNode(box: cc.Collider): void {
console.log("add:" + this.count);
if (this.cur_hit_node === null) {
this.cur_hit_node = box.node;
} else if (box.node.y < this.cur_hit_node.y) {
this.cur_hit_node = box.node;
}
}
protected updateCanvasHeight(): void {
let height: number = 0;
if (this.cur_hit_node) {
let actor_y: number = this.cur_hit_node.convertToWorldSpaceAR(cc.v2()).y;
let now_y: number = this.node.convertToWorldSpaceAR(cc.v2()).y;
height = actor_y - now_y;
} else {
let canvas: cc.Node = cc.Canvas.instance.node;
let pos: cc.Vec2 = canvas.convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v2()));
height = canvas.height / 2 - pos.y;
}
this.updateHeight(height);
}
protected updateHeight(value: number) {
let box: cc.BoxCollider = this.hitbox as cc.BoxCollider;
this.node.height = this.sp.node.height = value;
box.offset.y = value / 2;
box.size.height = value;
}
// update (dt) {}
}
就先普通的一张图片拉伸的出来的激光,用的2.4只能弄这种
我们这边是开始发射时长度从 0 开始,逐渐变长,与敌人发生碰撞停止变长
大佬,我之前做过类似的,只是我的激光是在短时间内变长的,也就是说他有一个增长速度,碰到敌机就会截断,敌机消失或者从敌机移开,就会以一定速度增长,可能就不会出现你说的闪一下的情况吧
好的,我看其他游戏不像那种增长的,所以就没考虑这种情况。先就这种吧,3.x里面有个line组件,可惜2.x里面没得
可以考虑增长速度非常快?没有尝试过,不知道会不会导致碰撞判断出问题
该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。