- 最后登录
- 2022-10-8
- 注册时间
- 2010-12-6
- 阅读权限
- 100
- 积分
- 14150
- 纳金币
- 76544
- 精华
- 23
|
1. 注册侦听器
Java代码
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
2. MouseDown触发函数
Java代码
// 保存鼠标点击的摄像机参数和鼠标坐标信息
private function onMouseDown(event:MouseEvent):void
{
lastPanAngle = camera.panAngle;
lastTiltAngle = camera.tiltAngle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
move = ***e;
stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
// 保存鼠标点击的摄像机参数和鼠标坐标信息
private function onMouseDown(event:MouseEvent):void
{
lastPanAngle = camera.panAngle;
lastTiltAngle = camera.tiltAngle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
move = ***e;
stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
3. MouseUp触发函数
Java代码
private function onMouseUp(event:MouseEvent):void
{
move = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onMouseUp(event:MouseEvent):void
{
move = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
4. 每帧都调用的onEnterFrame
Java代码
private function onEnterFrame(event:Event):void
{
if (move) {
camera.panAngle = 0.3*(stage.mouseX - lastMouseX) + lastPanAngle;
camera.tiltAngle = 0.3*(stage.mouseY - lastMouseY) + lastTiltAngle;
}
camera.hover();
view.render();
}
private function onEnterFrame(event:Event):void
{
if (move) {
camera.panAngle = 0.3*(stage.mouseX - lastMouseX) + lastPanAngle;
camera.tiltAngle = 0.3*(stage.mouseY - lastMouseY) + lastTiltAngle;
}
camera.hover();
view.render();
}
更多Flash3D编程技巧分享尽在web3D纳金网http://www.narkii.com/ |
|