This commit is contained in:
2024-07-30 08:34:41 +08:00
parent fe09fb1f5f
commit 76b400885c
11 changed files with 43 additions and 28 deletions

View File

@@ -23,7 +23,9 @@ export class MonsterViewComp extends CCComp {
/** 角色动画 */
as: MonsterSpine = null!;
speed: number = 100;
ospeed: number = 100;
Tpos: Vec3 = v3(0,-60,0);
timer: number = 0;
/** 视图层逻辑代码分离演示 */
start () {
// 注册单个碰撞体的回调函数
@@ -43,13 +45,11 @@ export class MonsterViewComp extends CCComp {
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体开始接触时被调用一次
// console.log('monster Contact,otherCollider',otherCollider);
this.speed = 0;
this.timer = 1;
switch (otherCollider.group) {
case BoxSet.HERO:
console.log('monster coolider hero');
break;
case BoxSet.HERO_SKILL:
console.log('monster coolider hero skill');
// console.log('monster coolider hero skill');
break;
default:
break;
@@ -58,11 +58,17 @@ export class MonsterViewComp extends CCComp {
onLoad() {
this.as = this.getComponent(MonsterSpine);
console.log('this.ospeed:',this);
}
update(dt: number){
if(this.timer > 0){
this.timer -= dt;
if(this.timer <= 0){
this.speed = this.ospeed;
this.timer = 0;
}
}
if(this.node.position.x > -360){
this.move(dt);
}