Flash3D 编程技巧:全景浏览的键盘交互(Away3D)

创建三个侦听:

this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
this.stage.addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
this.addEventListener(Event.ENTER_FRAME,onEnterFrame);

 

onKeyDown:

private function onKeyDown(e:KeyboardEvent):void
{
	lastKey = e.keyCode;
	keyIsDown = true;
}

 

onKeyUp:

private function onKeyUp(e:KeyboardEvent):void
{
	keyIsDown = false;
}

 

onEnterFrame:

private function onEnterFrame(e:Event):void
{
	if(!cover.visible)
	{
		if(keyIsDown){
			// if the key is still pressed, just keep on moving
			switch(lastKey){
				case Keyboard.UP	: cam.targettiltangle -= 5; break;
				case Keyboard.DOWN	: cam.targettiltangle += 5; break;
				case 87				: cam.zoom += 0.3; break;
				case 83				: if(cam.zoom > 1.4){cam.zoom -= 0.3}; break;
				case Keyboard.LEFT	: cam.targetpanangle -= 5; break;
				case Keyboard.RIGHT	: cam.targetpanangle += 5; break;
			}
		}
		// render the view
		cam.hover();
		View.render();
	}
}
 

 

 

 

你可能感兴趣的:(编程,UP)