您的位置: 首页-> 电脑文摘-> 图象图形-> Director-> 正文

用Director创建涂色板
作者佚名 来源InterNet 加入时间:2005-2-7
过去,用Director创建涂色板类型的项目需要做许多前期工作。除了制作线条以外,还必须给每个将被涂色的元素创建隔离演员,并且为每个角色创建涂色代码。

  幸运的是,在Director 8.5中使用floodFill这一非正式的图像Lingo命令即可克服这些困难。floodFill命令能够接受传递的location值和color值,并使用这个指定的颜色填充图像(非常类似于在Paint Window中使用颜料桶工具),此命令的语法类似这样:

imageObj.floodFill (x, y, colorObj) 或 imageObj.floodFill (point (x,y), colorObj)

  第一个参数是填充时开始点的位置,第二个参数是填充时使用的颜色对象。

  创建涂色板应该从制作简单的黑色线条开始,在Paint Window中即可完成这步。接下来,需要为想要使用的每个颜色创建一个隔离演员。为颜色样本编写如下代码:

on beginSprite me
  sprite (me.spriteNum).cursor = 281
  tempImage = sprite (me.spriteNum).member.image
  tempImage.floodFill (point (1,1), pColor)
  tempImage.draw (tempImage.rect, [#shapeType: #rect, #lineSize: 1, #color: color (#rgb, 0, 0, 0)] )
end

on mouseUp me
  sendAllSprites (#setNewColor, pColor)
end

  首先,beginSprite将角色上的鼠标形状设置为为281(滴管),并创建一个名为tempImage的变量指向当前演员的图像。此时,floodFill命令使用选择的颜色填充此图像,并绘制一条黑色边界以固定颜色样本的形状。最后,在mouseUp处理程序中,颜色样本的特定信息被发送给每一个角色。

  行为中另一个名为setNewColor的处理程序将接收每一个颜色样本发送的颜色信息:

on setNewColor me, whichColor
  pColor = whichColor
end

  对于行为的其余部分,需要先初始化一些东西。

On beginSprite me
  pColor = 0
  sprite (me.spriteNum)Cursor = 259
  pMemRef = sprite (me.spriteNum).member
  pMemRef.image = member ("coloringBook").image.duplicate ()
  pMemRef.regpoint = point (0,0)
end

  首先,令pColor=0,表示还没有选取任何颜色。其次,将角色上的鼠标形状设置为259(颜料桶)。此时创建一个名为pMemRef的变量指向相应的演员,并将此演员的图像设定为演员“coloringBook ”(即包含黑色线条的那个演员)的图像。最后,将此演员的注册点设置为point (0,0)以方便此后的计算。

  下面的代码在鼠标点击时填充图像:

On mouseUp me
  if pColor <> 0 then
    offsetLoc = the clickLoc - sprite (me.spriteNum).loc
    pixelColor = pMemRef.image.getPixel (offsetLoc, #integer)
    if pixelColor > 0 then
      pMemRef.image.floodFill (offsetLoc, pColor)
    end if
  end if
end

  首先,这些代码确定pColor值不为0,以保证用户已经选取了某个颜色。其次,将鼠标点击处的location值减去角色的location值,以计算出点击处相对于图像的location值。接下来,获得点击处像素的颜色值并将其作为一个整数型常量存储。如果不为黑色,意味着用户并没有点击黑色线条,此时floodFill命令根据指定的颜色填充图像。


[文章录入员:nancy]

相关文章
  • Director小技巧
  • Director中各种内部事件发生的顺序
  • 控制动画GIF
  • 在Director中使用PowerPoint档案
  • 认识Director中的Xtra
  • Director8行为库的应用
  • Director中控制声音音量的几种方法
  • flash和director之间的沟通技巧
  • director应用技巧
  • Director怎样制作自定义光标
  • 相关软件:
  • Director8.0行为库中文说明
  • ::PCBOOKCN'ADS::


    ::Director::
    PhotoShop
    CorelDraw
    3D-MAX
    AutoCAD
    FreeHand
    Illustrator
    Authorware
    Director
    Maya/Rhino
    其它
    ::阅读排行::
    ·内存中对象的配置
    ·在Director中使用Powe...
    ·音频与数字视频、flash音频的...
    ·Director小技巧
    ·控制动画GIF
    ·认识Director中的Xtra
    ·Director中各种内部事件发...
    ·用Lingo解决组合问题
    ·Director8行为库的应用
    ·行为库创建技巧