频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

【Director教程】用距离控制声音

来源: 作者: 出处:巧巧读书 2007-10-09 进入讨论组

  (只是想为多媒体的发展尽一份力。以下是翻译director online 上的一篇关于用距离控制声音的文章,觉得简单有用,所以给大家共享。动机单纯。-------alalala)

  我需要将一张图片放到舞台的中央,以便鼠标靠近的时候声音会马上淡入,同时图片做淡入淡出的发光效果。
  还记得高中学过的几何学如何计算直角斜边的长度吗?我们来回顾一下。假设你知道了两条直角边x,y。计算第三条边的长度的公式是

  X2 + Y2 = Z2

  很容易得出z的长度始终大于x或y的长度。

  现在我们把它应用到你问题中去。设想一下直角边的斜边z由你的精灵的坐标和鼠标的坐标来决定。x是你的精灵和鼠标的水平距离,y是你的精灵和鼠标的垂直距离。现在,以上的公式可改为


set x = the mouseH - the locH of sprite whatever
set y = the mouseV - the locV of sprite whatever
x2 + y2 = the distance2

  这就是我们要用的概念。因为距离永远不可能为负数,当我们编写lingo的时候,我们使用绝对值属性来设定x和y。同时,我亲向于使用描述性的变量来定义x,y。在这个例子中我将使用hinc和vinc来表示“水平增量和垂直增量”。

  接下来的步骤就是是这个距离和以下的事件关联:1)声音通道的音量。2)精灵的混合值(发光的精灵)。音量的范围是从0到255,既然我们希望声音在鼠标接近的时候增加,我们可以简单的制定音量等于255减去距离。为了增强可操作性,我创建了“fade\"变量。我们使用“fade\"变量来乘以距离,这样我们可以使音量在较短的距离里增减。(fade的值越大,变化的越快)。

  最后,你需要改变墨水的混合值,来实现发光的效果。在这个行为里,我们让这个混合值与音量关联。混合值由1到100,为了使它适应音量的0到255的变化范围,我们设定混合值为 数值/256。


  以下便是这个行为。你需要制定一下发光的精灵。


property pMyLocH
property pMyLocV
property pFade
property pSoundChannel
property pMySprite

on getPropertyDescriptionList me
set pdlist to [:]
set the floatPrecision to 1
addprop pdlist, #pFade, [#comment:\"Rate of fade\", #format:#float, #default:3.0]
addprop pdlist, #pSoundChannel, [#comment:\"Which sound channel\", #format:#integer, #default:1]
return pdlist
end getPropertyDescriptionList

on beginSprite me
set pMySprite = the spriteNum of me
set pMyLocH = the locH of sprite pMySprite
set pMyLocV = the locV of sprite pMySprite
set the blend of sprite pMySprite to 0
end

on exitframe me
set hInc = abs(the mouseH - pMyLocH)
set vInc = abs(the mouseV - pMyLocV)

set distance = sqrt((hInc * hInc) + (vInc * vInc))
set the volume of sound pSoundChannel = 255 -(distance * pFade)
set the blend of sprite pMySprite = the volume of sound pSoundChannel/2.56
end

浏览地址: http://www.qqread.com/director/f345137.html 更多文章 更多内容请看ASP.NET教程FreeBSD使用教程专题,或进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章