作者chang162015 (快樂越來越模糊)
看板Flash
標題[問題] 求場景隨滑鼠左右移動 AS3語法
時間Mon Jun 13 20:12:48 2011
http://kongzi.sina.com.cn/jian/index.html
我想求效果跟這個一樣的AS3語法
目前剛從as2轉as3
整個跟as3很不熟阿...
上網找很久也只找到AS2的...
拜託了>"<
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.131.113
1F:推 peacedove:mouseX mouseY 06/13 20:14
2F:推 p52189:要移動的東西用個Sprite包起來 然後監聽滑鼠 06/14 03:05
3F:推 KawasumiMai:好不切實際的網站.....肥大過頭了..... 06/14 11:39
4F:→ allenmusic:用addchild 06/14 16:15
謝謝大家!!!
最後我找了好幾本書終於找到
我現在的寫法是
var centerx:int = stage.stageWidth/2;
this.x = 0;
this.addEventListener(Event.ENTER_FRAME, mEnterFrame);
function mEnterFrame(e:Event):void {
var dx:int = stage.mouseX - centerx;
this.x -= dx*0.06;
if (this.x >0) {
this.x = 0;
} else if (this.x<stage.stageWidth-this.width) {
this.x = stage.stageWidth-this.width;
}
}
可以再請教一下
如果我想讓他在滑鼠靠近左邊以及右邊時才會移動
中間大部分的區域是不會移動的
這樣的語法該從哪裡修改呢??
目前的實力還只能套套語法而已..
謝謝大家的幫忙=)
※ 編輯: chang162015 來自: 114.32.131.113 (06/14 18:17)
5F:推 dsmwang:用個if限制dx的設定 06/14 21:48
6F:推 allenmusic:if(stage.mouseX>500 || stage.mouseX<50){要執行 } 06/15 06:58
7F:→ allenmusic:500<改成你要的左邊 50改成你要的右邊範圍 -.- 06/15 06:59
8F:推 scars:原文if裡面的大小於是不是寫反 06/15 09:48
9F:→ scars:沒事 我看錯惹~ 06/15 09:48
真的非常感謝!!
※ 編輯: chang162015 來自: 114.32.131.113 (06/16 21:37)