下面介紹一個(gè)用來(lái)檢測(cè)餅圖顏色的簡(jiǎn)單例子。
首先在paint窗口中畫(huà)彩色餅圖,保存為“circle”,在text窗口中作輸入文本“the color is:”,并保存為“textbar”。
將上面兩個(gè)劇組成員拖到舞臺(tái)上,設(shè)置他們的屬性。將餅圖墨水效果設(shè)置為“matte”或“background transparent”,消除白色邊框。在總譜中將兩個(gè)成員的長(zhǎng)度均設(shè)為一幀,放置在第一幀。
在電影腳本中輸入如下初始化腳本:
global _color, _text
on startmovie
_text = "the color is: "
_color = rgb(0,0,0)
member("textbar").alignment = #center
member("textbar").text = _text
end
下面分析一下取色方法。要求當(dāng)鼠標(biāo)點(diǎn)擊在餅圖上時(shí)必須實(shí)時(shí)檢測(cè)出顏色值。因?yàn)橛捌?0幀每秒的速率播放,也就是說(shuō)在一幀上每秒可以檢測(cè)30次鼠標(biāo)事件并作出相應(yīng)判斷,這對(duì)于鼠標(biāo)事件來(lái)說(shuō)時(shí)間已經(jīng)足夠短了。
雙擊第一幀的腳本通道,在幀腳本中輸入如下腳本:
on exitframe me
check --檢測(cè)鼠標(biāo)事件并在當(dāng)前幀循環(huán)
go the frame
end
on check
global _color, _text
repeat while the mousedown --檢測(cè)鼠標(biāo)按鍵
if the mousemember <> member("circle") then --如果鼠標(biāo)沒(méi)有
--選中調(diào)色餅
exit --則退出
end if
--得到相對(duì)于調(diào)色餅的鼠標(biāo)點(diǎn)的位置,并取該點(diǎn)顏色值
--注意計(jì)算該點(diǎn)時(shí),是用鼠標(biāo)位置減去調(diào)色餅的左上角坐標(biāo),
--而不是調(diào)色餅的位置loc
_loc = the mouseloc - point(sprite(1).rect[1],sprite(1).rect[2])
_color = member("circle").image.getpixel(_loc)
--如果取色為黑色或白色,則退出,這樣可以保證只有鼠標(biāo)點(diǎn)中餅圖時(shí)才
--檢測(cè)到顏色
if (_color = rgb(0,0,0)) or (_color = rgb(255,255,255)) then
exit
end if
--在文本框中顯示顏色值,并改變文本框背景色為選取色
member("textbar").text = _text &return& _color
sprite(2).bgcolor = _color
updatestage
end repeat
end
現(xiàn)在可以編譯運(yùn)行了。效果如下圖所示。這個(gè)例子沒(méi)有什么特別的技巧,只需要了解事件觸發(fā)機(jī)制和前面介紹的影片運(yùn)作方式,很快就可以做出來(lái)。
新聞熱點(diǎn)
疑難解答