看板 Flash 關於我們 聯絡資訊
※ 引述《Isacat (日光貓....^o.o^)》之銘言: : AS2問題。 : 載入數個物件,要設定其座標在一"圓形"的範圍內的隨機位置。 : 該怎麼做呢? : 我只知道如何在一個矩形的範圍內出現,ex: : for ( i=1; i<=30; i++ ){ : minX = tree_mc._x ; : maxX = tree_mc._x + tree_mc.area_mc._width; : minY = tree_mc._y; : maxY = tree_mc._y + tree_mc.area_mc._height; : attachMovie( "apple", "apple"+i, i); : this["apple"+i]._x = Math.floor ( (maxX-minX)*Math.random()+minX ); : this["apple"+i]._y = Math.floor ( (maxY-minY)*Math.random()+minY ); : } : 可是這樣子我的蘋果會飛到蘋果樹外面...囧 : 好煩惱~"~ : 請問該怎麼改呢? 試試看這樣: radius = 200; //半徑 for(i=0; i<100; i++) { theta = Math.random() * 360 * Math.PI / 180; //隨機的角度 XX = (200 + Math.cos(theta) * Math.random() * radius); //這裡的200是微調的 YY = (200 + Math.sin(theta) * Math.random() * radius); //同上 attachMovie("obj", "obj" +i, this.getNextHighestDepth(), {_x:XX, _y:YY}); } -- 腦袋不太清楚.. 畫出來好像不太圓 有錯再請糾正 -- 誠徵PHP網站工程師,熟MVC架構 http://blog.eddie.com.tw/ 全職、兼職可,意者請敲 :) http://www.eddie.com.tw/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.128.37
Isacat:我的蘋果長在蘋果樹上了 感謝解答 05/13 07:06