![]() |
|
|
![]() |
| 作者:佚名 文章来源:互联网 点击数: 更新时间:2008-3-3 | |||
|
|
|||
|
本节将介绍一个键盘控制实例,程序中主要使用了4个方向键,当按下方向键时,动画演员的位置随之产生移动。
(1) 进入Director 8.5。执行Modify→Movie→Properties命令,在弹出的舞台属性检查器对话框中将电影舞台的大小设置为500×375,将背景颜色设置为白色,如图7-159所示。
图7-159 设置舞台的属性 (2) 按Ctrl+R组合键,导入2张图片,在Cast窗口中显示,如图7-160所示。
图7-160 导入2张图片 (3) 将Cast演员1和2拖动到舞台上,生成精灵1和精灵2,效果如图7-161所示。
图7-161 生成精灵1和精灵2 (4) 要控制4个方向键,就首先要知道方向键对应的数值,这需要先测试。单击工具栏中的Script按钮,弹出Script窗口,输入以下测试程序,如图7-162所示。 on keyDown put keycode() end keyDown
图7-162 输入测试程序 (5) 在帧脚本中让电影停留在某一帧,以保证有时间进行测试,输入以下帧Lingo脚本程序,如图7-163所示。 on exitFrame me go to the frame end
图7-163 帧Lingo脚本程序 (6) 执行Window→Message命令,打开Message(消息)窗口。运行程序,并依次按下键盘上的:“↑”、“↓”、“←”、“→”4个方向键,在其窗口中可以看到按键的数值被检测出来,如图7-164所示。
图7-164 Message窗口中的信息 (7) 双击Script通道的第28帧,打开Script窗口,输入以下Lingo语句,如图7-165所示。 global positionx global positiony on exitFrame me go to the frame end on keyup positionx=the loch of sprite 2 positiony=the locv of sprite 2 case the keycode of 123: set the loch of sprite 2 to positionx–5 124: set the loch of sprite 2 to positionx+5 125: set the locv of sprite 2 to positiony+5 126: set the locv of sprite 2 to positiony-5 end case end
图7-165 第2帧的Lingo脚本 (8) 至此,键盘控制动画的制作完成了,播放电影,效果如图7-166所示。 本节实例很简单,可以举一反三创建出精彩的动画效果。
图7-166 键盘控制播放效果 |
|||
![]() |
|