|
查看: 1624|回复: 10
|
变换movieclip
[复制链接]
|
|
|
有哪里位大大知道我的问题出在哪里吗?为什么我的movieclip在滑鼠没有动时不会出现的?时有时没有
this.attachMovie('laydown','dog' ,this.getNextHighestDepth());
dog._xscale = 50;
dog._yscale = 50;
dog._x = Stage.width/2;
dog._y = 280;
var match = new Boolean(false);
pos = 0;
onMouseMove = function() {
Mouse.hide();
var current_x = _xmouse;
checkDir(current_x, prev_x);
checkposition();
if(_xmouse >= 410){
dog._x = 410;
}else{
dog._x = _root._xmouse;
}
prev_x = current_x;
}
function checkDir(l, r){
if(l < r){
trace("L");
pos = 0;
}else if(l > r){
trace("R");
pos = 1;
}else{
trace("ntg");
pos = 2;
}
}
var inter = setInterval(checkDir, 10)
function checkposition(){
if (pos == 0) {
removeMovieClip(dog);
this.attachMovie('runL','dog' ,this.getNextHighestDepth());
}else if (pos == 1) {
removeMovieClip(dog);
this.attachMovie('runR','dog' ,this.getNextHighestDepth());
}else if(pos == 2){
removeMovieClip(dog);
this.attachMovie('laydown','dog' ,this.getNextHighestDepth());
}
}
[ 本帖最后由 mElO 于 14-4-2009 05:43 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 15-4-2009 12:31 AM
|
显示全部楼层
原帖由 mElO 于 14-4-2009 05:41 PM 发表 
有哪里位大大知道我的问题出在哪里吗?为什么我的movieclip在滑鼠没有动时不会出现的?时有时没有
this.attachMovie('laydown','dog' ,this.getNextHighestDepth());
dog._xscale = 50;
dog._yscale = 50;
dog ...
最好把你的檔案上傳方便帮你检查 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 15-4-2009 12:45 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 15-4-2009 05:46 PM
|
显示全部楼层
因為你編寫的 setInterval 結構方式和 onMouseMove 有衝突問題, 而且也沒有傳遞參數到 checkDir 函數
雖然 setInterval 已經把 pos 設定為 2 了, 但是卻沒有進行 checkposition 更新, 而你的 checkposition 更新是在 onMouseMove 的時候, 既然 onMouseMove 了就代表 _xmouse 會跟著變, 這時是先執行 checkDir 這樣一來你原本的 pos = 2 也就改變不再是 2, 除非是滑鼠只是上下移動完全沒改變到 _xmouse 才會看到 laydown 的 attachMovie
以下方式是捨棄 setInterval 對電腦計算和資源的耗用而選擇 setTimeout 的例子.
this.attachMovie('laydown', 'dog', 0, {_xscale:50, _yscale:50, _x : Stage.width/2), _y:280});
var prev_dir:Number = 0;
var prev_x:Number= 0;
var timeout:Number = 0;
Mouse.hide();
this.onMouseMove = function() {
clearTimeout(timeout);
var x:Number = _xmouse;
var dir:Number = x < prev_x ? 0 : 1;
//使用 dir 和 prev_dir 來美化 dog 的移動效果, 避免一直在執行 attachMovie
if(dir != prev_dir)
checkposition(dir);
dog._x = _xmouse >= 410 ? 410 : _xmouse;
prev_x = _xmouse;
timeout = setTimeout(this, "checkposition", 300, 2); //使用 setTimeout 在每次移動時候開始設定個時限, 要是沒有移動滑鼠也就不會執行以上的 clearTimeout, 跟著就會進入 checkposition 函數的執行了
updateAfterEvent();
}
function checkposition(pos){
if (pos == 0)
this.attachMovie('runL','dog', 0);
else if (pos == 1)
this.attachMovie('runR','dog', 0);
else if(pos == 2)
this.attachMovie('laydown','dog', 0);
dog._xscale = 50;
dog._yscale = 50;
dog._x = _xmouse >= 410 ? 410 : _xmouse;
dog._y = 280;
prev_dir = pos;
prev_x = dog._x;
}
p/s1: AS 2.0 定義 true false 只要寫成 var match:Boolean = false 即可
p/s2: 初始變數有些有 var 有些沒有, 更有些沒有初始(如 prev_x), 該養成習慣每個變數都先初始之後并加上 var |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 15-4-2009 10:18 PM
|
显示全部楼层
回复 4# super-tomato 的帖子
|
谢谢你,不过想问问你如何停止控制狗的方向或者停止整个游戏?比如说game over了。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 16-4-2009 12:06 AM
|
显示全部楼层
原帖由 mElO 于 15-4-2009 10:18 PM 发表 
谢谢你,不过想问问你如何停止控制狗的方向或者停止整个游戏?比如说game over了。。。
當然就是停止所有能夠觸發的事件, 如 delete this.onMouseMove 或 this.onEnterFrame |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-4-2009 11:29 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 16-4-2009 02:12 PM
|
显示全部楼层
不明白你所說的不能立刻停止是指哪部分, 滑鼠移動的監聽事件確實已經停止了, 而且你的 interval 事件也刪除了 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-4-2009 04:19 PM
|
显示全部楼层
原帖由 super-tomato 于 16-4-2009 02:12 PM 发表 
不明白你所說的不能立刻停止是指哪部分, 滑鼠移動的監聽事件確實已經停止了, 而且你的 interval 事件也刪除了
你可以试看如果狗狗碰到炸弹的时候就能看到了。。。我需要的是如果狗狗碰到炸弹的时候, 狗狗就会烧焦而整个游戏就会停止。我有试看如果我快速的滑動滑鼠,狗狗烧焦的图会出现可是过后又会显示狗狗坐着的图。(只有在快速的滑動滑鼠的时候才会出现) |
|
|
|
|
|
|
|
|
|
|
发表于 16-4-2009 05:02 PM
|
显示全部楼层
原帖由 mElO 于 16-4-2009 04:19 PM 发表 
你可以试看如果狗狗碰到炸弹的时候就能看到了。。。我需要的是如果狗狗碰到炸弹的时候, 狗狗就会烧焦而整个游戏就会停止。我有试看如果我快速的滑動滑鼠,狗狗烧焦的图会出现可是过后又会显示狗狗坐着的图。(只 ...
function exploded(){
clearInterval(inter);
delete this.onMouseMove;
clearTimeout(timeout); //要清除 timeout 事件避免 onMouseMove 尚未執行 clearTimeout
this.attachMovie('explode', 'dog', 0, {_xscale:50, _yscale:50, _x:dog._x, _y:280});
Mouse.show();
} |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 16-4-2009 05:07 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|