Flash与3D编程探秘(六)- 全方位旋转摄像机
2008-11-12 11:51:10 来源:WEB开发网7. 写一个循环函数,不停的调用第6步的函数刷新所有的小P。如果你一直有看文章的话那么这些对你来说应该不难。
//looptoupdatethescreen
functionrun(e:Event)
{
for(vari=0;i<scene.numChildren;i++) //updatealltheballsonthescreen
{
display(scene.getChildAt(i));
}
swap_depth(scene);
}
//bubblesortalgo
functionswap_depth(container:Sprite)
{
for(vari=0;i<container.numChildren-1;i++)
{
for(varj=container.numChildren-1;j>0;j--)
{
if(Object(container.getChildAt(j-1)).z_near<Object(container.getChildAt(j)).z_near)
{
container.swapChildren(container.getChildAt(j-1),container.getChildAt(j));
}
}
}
}
8. 最后是设置一些键盘和鼠标事件响应函数,完成我们的程序。
functionkey_down(e:KeyboardEvent):void
{
if(e.keyCode==65) //a
pan_left=true;
if(e.keyCode==68) //d
pan_right=true;
if(e.keyCode==87) //w
pitch_up=true;
if(e.keyCode==83) //s
pitch_down=true;
}
functionkey_up(e:KeyboardEvent):void
{
if(e.keyCode==65)
pan_left=false;
if(e.keyCode==68)
pan_right=false;
if(e.keyCode==87)
pitch_up=false;
if(e.keyCode==83)
pitch_down=false;
}
functionkey_response(e:Event):void
{
if(pan_left)
camera.panning-=0.01;
if(pan_right)
camera.panning+=0.01;
if(pitch_up)
camera.pitching-=0.01;
if(pitch_down)
camera.pitching+=0.01;
if(mouse_ctl) //ifallowmousecontrolpanandpitch
{
camera.panning+=scene.mouseX/22000;
camera.pitching+=scene.mouseY/22000;
}
//limitthepitchandtilt
if(camera.pitching<-1*PI/3)
camera.pitching=-1*PI/3;
if(camera.pitching>PI/3)
camera.pitching=PI/3;
}
functionclicked(e:Event) //togglemousecontrol
{
mouse_ctl=!mouse_ctl;
}
//setupeventlisteners
this.addEventListener(Event.ENTER_FRAME,run);
this.addEventListener(Event.ENTER_FRAME,key_response);
stage.addEventListener(KeyboardEvent.KEY_DOWN,key_down);
stage.addEventListener(KeyboardEvent.KEY_UP,key_up);
stage.addEventListener(MouseEvent.CLICK,clicked);
- ››FLASH不等于运算符!=的使用实例
- ››FLASH不全等运算符!==
- ››FLASH字符串分隔符运算符
- ››FLASH% 模运算符
- ››Flash+、++、+= 加法运算符
- ››Flash, 逗号运算符
- ››flash中的-、--、-=减法运算符
- ››Flash的-Infinity 常数、.点运算符、/ 除法运算符...
- ››Flash两种注释方法/*..*/ 和// 注释行分隔符运算符...
- ››Flash的/=除法赋值运算符、=赋值运算符、== 等于运...
- ››Flash之?: 条件运算符、^ 按位 XOR 运算符、^= 按...
- ››Flash的_framesloaded代码示例
更多精彩
赞助商链接