在createjs上鼠标上按鼠标x

时间:2015-09-04 10:01:16

标签: createjs

我在剪辑中有图片

我要做的是: 当鼠标位于父剪辑上方时,我希望图形移动/跟随鼠标的方向, 到目前为止我有什么

exportRoot.game_anim.meterMC.addEventListener("mouseover",function (evt) {

var _this = evt.target.arrowYou
console.log(evt.target.arrowYou)
var mouseRight = 0;
var mouseLeft = 180;

 var offset = {x: _this.x - evt.stageX, y: _this.y - evt.stageY};

 evt.target.arrowYou.addEventListener("mousemove" , function(ev){
// )

 var pt = exportRoot.game_anim.meterMC.globalToLocal(stage.mouseX, stage.mouseY)

  if ( pt.y > mouseLeft){
    percent = 100;
} else if (pt.y < mouseRight){
    percent = 0;
} else {

    percent = Math.round(((pt.y - mouseRight) / (mouseLeft - mouseRight)*100));
_this.y = pt.y; 


}
 if ( pt.y > mouseLeft){ 

 }


setWheels(percent)


   })

 });

1 个答案:

答案 0 :(得分:0)

解决了它。

我没有把函数放在一个eventlistener中,而是把它放在tick函数中。 使用globalToLocal跟踪mouseX并将嵌套图形设置为

function controlArrows(){
  if(gameStarted == true){
    var mouseRight = 0;
    var mouseLeft = 180;
    var arrowAwdY = exportRoot.game_anim.meterMC.awd.arrowAWD.y
percentAWD  = Math.round(((arrowAwdY) / (180)*100))
    var pt = exportRoot.game_anim.meterMC.globalToLocal(stage.mouseX, stage.mouseY)
 if (pt.y > mouseLeft){
    percent = 100;
    } else if (pt.y < mouseRight){
    percent = 0;
    } else {
 percent = Math.round(((pt.y - mouseRight) / (mouseLeft - mouseRight)*100));
 exportRoot.game_anim.meterMC.arrowYou.y = pt.y;    
 setWheels(percent)
      }
   }    
}   
相关问题