[]Tween.to 执行失败
//使精灵走到鼠标位置不知道为什么精灵没有动,精灵的坐标会变成NaN
function walkToMousePos(sprite){
console.log(Laya.stage.mouseX) ;
console.log(Laya.stage.mouseY) ;
console.log(sprite.x) ;
console.log(sprite.y) ;
var hDir = Laya.stage.mouseX>sprite.x? "right" : "left" ;
var vDir = Laya.stage.mouseY>sprite.y? "down" : "up" ;
//先横着走,走完之后调用竖着走的函数
Tween.to(sprite,{x:Laya.stage.mouseX,y:sprite.y,update:new Handler(this,onWalk(hDir)),complete:Handler.create(this,function(){
Tween.to(sprite,{x:sprite.x,y:Laya.stage.mouseY,update:new Handler(this,onWalk(vDir))}) ;
})}) ;
console.log(sprite.x) ;
console.log(sprite.y) ;
console.log("once done") ;
}
function onWalk(dir){
switch(dir){
case "up":
hero_p1.roleAni.play(0,true,"p1_walk_up");
Laya.stage.addChild(hero_p1.roleAni);
break ;
case "down":
hero_p1.roleAni.play(0,true,"p1_walk_down");
Laya.stage.addChild(hero_p1.roleAni);
break ;
case "left":
hero_p1.roleAni.play(0,true,"p1_walk_left");
Laya.stage.addChild(hero_p1.roleAni);
break ;
case "right":
hero_p1.roleAni.play(0,true,"p1_walk_right");
Laya.stage.addChild(hero_p1.roleAni);
break ;
}
}
输出如下:
0
0
once done
80
135
NaN
NaN
NaN
NaN
once done
没有找到相关结果
已邀请:
要回复问题请先登录
3 个回复
mtjss2
赞同来自:
mtjss2
赞同来自:
Laya_XS
赞同来自: