[問題] 關於準確吸附目標
不好意思,把整個程式碼PO上來
因為我真的試了好久好久好久好久好久
從晚上試到天亮,怎樣弄就是不行
到底是發生什麼問題了
真的麻煩有心的大大幫小弟解決這個長久的煩惱
小弟在做的是資料結構的雙向鏈結
就是一台車,有兩個箭頭(前&後),可以去"指向"其他的車
大概長這樣 <-(XXX)->
然後當拖曳箭頭去"指向"其他車的時候會吸附上去
簡單說,就是當車子上的箭頭去碰撞到其他的車子,箭頭就會吸附到上面
可是小弟一直發生的問題
不管怎樣碰撞,明明碰撞成功,卻吸附到自己的車上去,而不是對方
var container:Sprite=new Sprite();//存車子
addChild(container);//容器放到舞台
new_btn.addEventListener(MouseEvent.CLICK,newbox);//產生車子的按鈕
function newbox(e:MouseEvent):void {
var tty:MovieClip=new TTY();//元件庫的車子
tty.x=125;//車子舞台座標
tty.y=50;
container.addChild(tty);//車子放到容器
tty.txt1.addEventListener(MouseEvent.MOUSE_DOWN,star);
tty.txt2.addEventListener(MouseEvent.MOUSE_DOWN,star);
tty.carbody0.addEventListener(MouseEvent.MOUSE_DOWN,star);
tty.carbody1.addEventListener(MouseEvent.MOUSE_DOWN,star);
tty.carbody2.addEventListener(MouseEvent.MOUSE_DOWN,star);
tty.txt1.addEventListener(MouseEvent.MOUSE_UP,onReleaseMouseUp);
tty.txt2.addEventListener(MouseEvent.MOUSE_UP,onReleaseMouseUp);
tty.carbody0.addEventListener(MouseEvent.MOUSE_UP,onReleaseMouseUp);
tty.carbody1.addEventListener(MouseEvent.MOUSE_UP,onReleaseMouseUp);
tty.carbody2.addEventListener(MouseEvent.MOUSE_UP,onReleaseMouseUp);
}
function onReleaseMouseUp(e:MouseEvent):void {
e.target.parent.stopDrag();
}
function star(e:MouseEvent):void {
e.target.parent.startDrag();
}
tty.dot1.addEventListener(MouseEvent.MOUSE_DOWN, onClcik1);//dot1車子前面的箭頭
tty.dot1.addEventListener(MouseEvent.MOUSE_UP, upClcik1);
function onClcik1(e:MouseEvent) {
e.target.startDrag();
}
//以下是重點問題程式碼(車子的箭頭可以自動拉長.縮短,AS在箭頭自己的影格內
應該不是這個的問題所以沒PO出來)
function upClcik1(e:MouseEvent) {
e.target.stopDrag();
var child:MovieClip;
for (var i = 0; i < container.numChildren; i++) {
child=MovieClip(container.getChildAt(i));
if (e.target!=child) {
if (e.target.hitTestObject(child)) {
//車子前面的箭頭碰到其他車子
e.target.x=child.x;
e.target.y=child.y;
}
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.240.129.149
→
11/21 18:41, , 1F
11/21 18:41, 1F
→
11/21 18:42, , 2F
11/21 18:42, 2F
→
11/21 18:42, , 3F
11/21 18:42, 3F
→
11/21 18:42, , 4F
11/21 18:42, 4F
※ 編輯: Friess 來自: 111.240.129.149 (11/21 19:01)
→
11/22 03:16, , 5F
11/22 03:16, 5F
→
11/22 03:18, , 6F
11/22 03:18, 6F
討論串 (同標題文章)
Flash 近期熱門文章
PTT數位生活區 即時熱門文章