Director全屏及按钮应用小小心得

来源:互联网 发布:大数据信息安全应用 编辑:程序博客网 时间:2024/05/11 14:35

  平时做课件,基本都用PPT,主要制作起来效率高(一个比较明显的案例:插入图片时可以先用抓图软件抓一下,然后Ctrl+V就OK了,够高效吧?),外加修改起来非常容易。因此,几乎不用Dir,也许是对它了解不够,掌握不深,运用不活的缘故吧。?
  如果稿子完全定型了才开始做课件,用Dir也有它的好处。一是处理动画可以比较随意,创意有多大,动画就有多炫,而且实现起来也相对方便。二是在安装了相关插件的情况下,用PS处理的素材不必再一张张地分别另存,直接导入PSD文件就行了,可以节省大量分解素材的时间。三是Dir支持脚本语言,在处理人机交互方面功能强大(开发三维游戏都可以,实现这点功能简直就是牛刀杀鸡,小菜一碟啦!)。
  近日用Dir做了一个课件,现学现用。有一点小小的心得,简要总结如下:
 

一、关于全屏的问题
  参考了一些资料,有让课件自动适应屏幕分辨率的例子,但都没有介绍如何还原。小分辨率的课件适应大分辨率的显示器时,会出现锯齿现象,清晰度下降,效果不是很好。因此,我希望能够全屏,也可以还原。方法如下:

 

--全屏
on mouseUp me  
  L=the desktoprectlist[1]
  if (the stage).rect<>L then
    (the stage).rect=L
    (the stage).drawrect=L
  end if
end

--还原为默认分辨率1024×768
on mouseUp me
  if (the stage).rect.width<>1024 then    
    L=rect(0,0, 1024, 768)    
    (the stage).rect=L   
    (the stage).drawrect=L
    _movie.centerstage=true  --舞台居屏幕中央
  end if 
end

 

二、按钮实用技术

(一)显示提示框
  当鼠标进入按钮时显示一个提示框,这样可以增强交互式课件的易用性,更加人性化。这需要提前制作好相应按钮的提示图片,放入一个通道,通过按钮脚本制作,使光标进入按钮时显示提示图片,光标离开时隐藏提示图片。方法如下(提示框在通17):

on mouseEnter me  --显示提示框
  Sprite(17).Visible=True
end

on mouseLeave me  --隐藏提示框
  Sprite(17).Visible=False
end
 

(二)改变按钮光标
  当光标进入按钮时,让光标变改形状,这样就可以让人很直观地知道光标是否已经进入了按钮的作用区域,更方便,更人性化。

on mouseEnter me
  cursor 280  --改变光标(手指,手掌为260)
end

on mouseLeave me
  cursor -1    --还原光标
end
 

(三)让按钮动起来
  一个静态的按钮,即使光标进入时改变鼠标形状,看起来仍难免有比较死板的感觉,如果能够让它动起来,那么它的交互性就会显得更加生动,界面也会更加有趣、吸引人。实现方法为:光标进入时,让按钮向上、向左移动1点,光标离开时再复原。代码如下:

on mouseEnter me
  --光标进入时改变位置,使按钮有动感
  set the loc of sprite the currentSpriteNum to point (902,726)
end

on mouseLeave me
  --光标离开时恢复按钮位置
  set the loc of sprite the currentSpriteNum to point (903,727)
end


综合使用上面三种技术,代码如下:
======================================
--【全屏及提示框控制】
======================================
--隐藏提示框(隐藏通道,用完需恢复)

on exitFrame me
  Sprite(17).Visible=False
  Sprite(18).Visible=False
end
--------------------------------------
--全屏
on mouseUp me
  L=the desktoprectlist[1]
  if (the stage).rect<>L then
    (the stage).rect=L
    (the stage).drawrect=L
  end if
end

on mouseEnter me
  Sprite(17).Visible=True
  cursor 302
  --光标进入时改变位置,使按钮有动感
  set the loc of sprite the currentSpriteNum to point (976,726)
end

on mouseLeave me
  Sprite(17).Visible=False
  cursor -1
  --光标离开时恢复按钮位置
  set the loc of sprite the currentSpriteNum to point (977,727)
end
--------------------------------------
--还原为默认分辨率
on mouseUp me
  if (the stage).rect.width<>1024 then
    L=rect(0,0, 1024, 768)
    (the stage).rect=L
    (the stage).drawrect=L
    _movie.centerstage=true  --舞台居屏幕中央
  end if
end

on mouseEnter me  --显示提示框
  Sprite(18).Visible=True
  cursor 303
  --光标进入时改变位置,使按钮有动感
  set the loc of sprite the currentSpriteNum to point (902,726)
end

on mouseLeave me  --隐藏提示框
  Sprite(18).Visible=False
  cursor -1
  --光标离开时恢复按钮位置
  set the loc of sprite the currentSpriteNum to point (903,727)
end
--------------------------------------
--恢复提示框所在通道精灵的可视性
on exitFrame me
  Sprite(17).Visible=True
  Sprite(18).Visible=True
end
 

由于提示框在默认状态下是不显示的,只有光标进入按钮时才显示,光标离开后又隐藏,因此,一开始就需要将提示框隐藏起来:
Sprite(17).Visible=False
用这个语句需要注意的是,它会将通道17的所有精灵都隐藏了,如果此后在17通道还有精灵,那么它们也被隐藏了,得不到显示。我只找到这样一个语句来控制,将通道号换成角色名,代码不能通过。没办法,只有让整个通道做牺牲了(如果哪位大虾知道,烦请告诉我一声!)。对此,可用两种方法来解决:
 

  1、将提示框放在单独的通道,即通道的编号最大,高过其他任何含有精灵的通道,这样即使隐藏了整个通道,也不会对其他角色产生影响;
 

  2、在提示框以外的区间,恢复通道的显示。如果按钮在主界面上,其他界面不显示该按钮,自然也就不需要提示框存在了,让它从该通道消失,放入其他需要的角色,并恢复通道显示:
Sprite(17).Visible=True
 

  3、根据跳转命令确定是否显示通道。假如现在停留在主界面,界面可以响应热键执行跳转命令,则可对帧脚本作如下改动:
 

--鼠标按键操作
on exitFrame me
  go to the frame
end
on  mouseUp     -- 鼠标左键下一步
  go to the frame+1
end
on rightMouseUp -- 鼠标右键上一步
  go to  marker(-1)
end

on keyUP
  case (the keyCode) of
    123: go(214)           -- ←TurnLeft(到开始画面)
         Sprite(19).Visible=True
         Sprite(20).Visible=True
    124: go(2820)          -- →TurnRight(到结束画面) 
         Sprite(19).Visible=True
         Sprite(20).Visible=True    
    125: go to the frame+1 -- ↓BackUp (前进)
    126: go to  marker(-1) -- ↑GoForward(返回一步)
         Sprite(19).Visible=True
         Sprite(20).Visible=True
  end case
  case the key of
    "0": go(214)           -- 到开始画面  
    "1": go(370)           -- 标题一 
         Sprite(19).Visible=True
         Sprite(20).Visible=True
    "2": go(750)           -- 标题二 
         Sprite(19).Visible=True
         Sprite(20).Visible=True
    "3": go(1370)          -- 标题三
         Sprite(19).Visible=True
         Sprite(20).Visible=True
    "9": go(2820)          -- 到结束画面
         Sprite(19).Visible=True
         Sprite(20).Visible=True     
  end case 
end
当然,如果有按钮执行跳转的,也要根据情况加入是否显示提示框所在通道的命令。
 

  4、在对每帧都进行判断。比如我的主界面停留在第214帧,只在这里使用17、18通道的提示框,则可在提示框出现的前一帧(如212帧)将其隐藏,然后对其他所有停顿的帧进行判断,添加如下脚本:
 

on exitFrame me
  a=the frame 
  if (a<>214)then      
    Sprite(19).Visible=True
    Sprite(20).Visible=True
  end if
  go to the frame
end
 

  Director的功能是非常强大的,加上支持Lingo和JavaScritp两种脚本语言,可以实现无限的创意来。但如何灵活利用它有限的功能,来充分为我们无限的创意服务,还是值得?深思的。

原创粉丝点击