@flybin 写道:
cocos 3d 如何在一直按下鼠标中键的时候,获得鼠标的位置,想做相机随着鼠标进行移动,谢谢~
cocos 3d代码:
update(deltaTime: number){
if (this.isMOUSE_WHEEL)
{ cc.log("鼠标中键按下");cc.log(this.MOUSE_WHEELLocationX,this.MOUSE_WHEELLocationY,this.PreMouseMPosX);if (this.PreMouseMPos.x <= 0) { this.PreMouseMPos = new Vec3(this.MOUSE_WHEELLocationX,this.MOUSE_WHEELLocationY, 0.0); } else { var CurMouseMPos:Vec3 = new Vec3(this.MOUSE_WHEELLocationX,this.MOUSE_WHEELLocationY, 0.0); var offset:Vec3 = new Vec3(CurMouseMPos.x - this.PreMouseMPos.x,CurMouseMPos.y - this.PreMouseMPos.y,CurMouseMPos.z - this.PreMouseMPos.z); offset =new Vec3(-offset.x * 10,-offset.y * 10,-offset.z * 10) ;//0.1这个数字的大小可以调节速度 this.node.translate(offset); this.PreMouseMPos = CurMouseMPos; } } else { // this.PreMouseMPosX = 0; } }
//鼠标中键按下,上下左右移动相机
onMOUSE_DOWN(event: EventMouse)
{
//鼠标中键按下,上下左右移动相机
if (event.getButton() === 1)
{
this.MOUSE_WHEELLocationX= event.getLocationX();
this.MOUSE_WHEELLocationY =event.getLocationY();this.isMOUSE_WHEEL=true; } }
一直按下的鼠标中键的时候,移动鼠标,event.getLocationX();的值不进行变化,求指导,谢谢~
帖子: 1
参与者: 1