dd
This commit is contained in:
@@ -37,7 +37,9 @@ export class Monster extends ecs.Entity {
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,camp:number = 1,prefab_path:string = "monster",name:string="hero") {
|
||||
var path = "game/monster/"+prefab_path;
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/monster/hero";
|
||||
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
var scene = smc.map.MapView.scene;
|
||||
@@ -47,7 +49,7 @@ export class Monster extends ecs.Entity {
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.setPosition(pos)
|
||||
console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
|
||||
const url = 'game/heros/hero/'+name+'/spriteFrame';
|
||||
const url = 'game/heros/hero/'+prefab_path+'/spriteFrame';
|
||||
resources.load(url, SpriteFrame, (err: any, spriteFrame) => {
|
||||
const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
|
||||
|
||||
@@ -61,6 +61,9 @@ export class MonsterSpine extends Component {
|
||||
play(animName: string, loop: boolean): void {
|
||||
this.spine.setAnimation(0, animName, loop);
|
||||
}
|
||||
atk() {
|
||||
this.spine.setAnimation(0, "atk", false);
|
||||
}
|
||||
setAlpha(value: number): void {
|
||||
var color: Color = this.spine.color;
|
||||
color.a = 255 * (value / 1);
|
||||
|
||||
@@ -23,7 +23,22 @@ export default class MonsterSpineAnimator extends Component {
|
||||
// console.log("MonsterSpineAnimator start");
|
||||
this.playAnimation(this.animName, this.loop);
|
||||
}
|
||||
|
||||
mixTime:number= 0.2;
|
||||
|
||||
protected onLoad(): void {
|
||||
this.spine = this.getComponent(sp.Skeleton)!;
|
||||
// this.spine?.setMix('atk', 'move', this.mixTime);
|
||||
// this.spine?.setMix('move','atk', this.mixTime);
|
||||
this.spine.setEndListener(trackEntry => {
|
||||
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
|
||||
// console.log("[track %s][animation %s] end.", trackEntry.trackIndex, animationName);
|
||||
if (animationName == "atk") {
|
||||
this.spine.setAnimation(0, "move", true);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
lateUpdate(dt: number) {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ export class MonsterViewComp extends CCComp {
|
||||
speed: number = 100;
|
||||
/** 角色初始速度 */
|
||||
ospeed: number = 100;
|
||||
/**攻击速度 */
|
||||
atk_speed: number = 2;
|
||||
atk_cd: number = 0;
|
||||
/** 状态 1:move ,2: act 3: stop */
|
||||
state: number = 1;
|
||||
|
||||
Tpos: Vec3 = v3(0,-60,0);
|
||||
timer: number = 0;
|
||||
@@ -52,9 +57,10 @@ export class MonsterViewComp extends CCComp {
|
||||
case BoxSet.MONSTER:
|
||||
switch (otherCollider.tag){
|
||||
case BoxSet.HERO:
|
||||
this.state = 2;
|
||||
// console.log("im monster other is hero");
|
||||
this.speed = 0;
|
||||
this.timer = 1;
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
break;
|
||||
case BoxSet.HERO_SKILL:
|
||||
@@ -67,7 +73,7 @@ export class MonsterViewComp extends CCComp {
|
||||
case BoxSet.HERO:
|
||||
switch (otherCollider.tag){
|
||||
case BoxSet.MONSTER:
|
||||
|
||||
this.state = 2;
|
||||
break;
|
||||
case BoxSet.HERO_SKILL:
|
||||
|
||||
@@ -119,7 +125,7 @@ export class MonsterViewComp extends CCComp {
|
||||
|
||||
this.in_destroy();
|
||||
this.in_stop(dt);
|
||||
|
||||
this.in_act(dt);
|
||||
switch (this.type) {
|
||||
case 1:
|
||||
this.as.walk();
|
||||
@@ -133,9 +139,19 @@ export class MonsterViewComp extends CCComp {
|
||||
this.update_pos();
|
||||
|
||||
}
|
||||
|
||||
move(dt: number){
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.camp, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
in_act(dt: number) {
|
||||
if(this.atk_cd >= this.atk_speed){
|
||||
this.atk_cd = 0;
|
||||
this.as.atk();
|
||||
}
|
||||
if(this.state == 2){
|
||||
this.atk_cd += dt;
|
||||
}
|
||||
}
|
||||
/** 静止时间 */
|
||||
in_stop (dt: number) {
|
||||
if(this.timer > 0){
|
||||
|
||||
Reference in New Issue
Block a user