查看: 1495|回复: 6
|
[教學] 使用updateAfterEvent()
[复制链接]
|
|
作者 : Super-Tomato
發佈日 : 2006-05-15
updateAfterEvent一向來都甚少人使用﹐原因大多是Flash所提供的Actionscript Dictionary的說明沒附帶例子說明。
所以在這裡我提供了一個例子讓大家能夠了解到其用處。
首先﹐先來說明用處﹐一般上我們的所有指令動作都是根據framerate執行的。
而updateAfterEvent卻可以幫助我們不必等到下一個framerate才執行﹐這樣我們所看到的動作都相對的流暢很多。好啦﹐接下來就進入實做吧。
步驟一 :
打開新文件﹐然後更換 framerate 為 2﹐預設值是 12。 使用 2 的目的是為了確切讓我們看到 updateAfterEvent 的功效
步驟二 :
拷貝以下代碼﹐貼在第一個frame。
這段代碼是方塊跟隨鼠標移動而移動的指令
MovieClip.prototype.createRect = function(x:Number, y:Number, w:Number) {
with (this) {
lineStyle(1);
moveTo(x, y);
lineTo(x+w, y);
lineTo(x+w, y+w);
lineTo(x, y+w);
lineTo(x, y);
}
};
this.createEmptyMovieClip('mc', this.getNextHighestDepth());
mc.createRect(0, 0, 20);
mc.onMouseMove = function() {
this._x += (_xmouse - this._x) * .1;
this._y += (_ymouse - this._y) * .1;
}
步驟三 :
按 ctrl + enter 測試~~~ 移動鼠標的時候﹐是不是看到方塊一下就跳到鼠標附近的位置﹐感覺上很lagging呢?? 這就是我所說的﹐代碼的執行是根據framerate而更新。那麼接下來就加上這篇的主角 updateAfterEvent
步驟四 :
更正我們之前的代碼為
MovieClip.prototype.createRect = function(x:Number, y:Number, w:Number) {
with (this) {
lineStyle(1);
moveTo(x, y);
lineTo(x+w, y);
lineTo(x+w, y+w);
lineTo(x, y+w);
lineTo(x, y);
}
};
this.createEmptyMovieClip('mc', this.getNextHighestDepth());
mc.createRect(0, 0, 20);
mc.onMouseMove = function() {
this._x += (_xmouse - this._x) * .1;
this._y += (_ymouse - this._y) * .1;
updateAfterEvent();
}
步驟五 :
再次進行測試。。。。怎麼樣是不是效果差太多了呢??
那麼現在已經掌握到 updateAfterEvent 的用法了吧。。。。 |
|
|
|
|
|
|
|
发表于 15-5-2006 03:25 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 15-5-2006 11:11 PM
|
显示全部楼层
那是不是说,设为 12fps,updateAfterEvent()就没有效果了? |
|
|
|
|
|
|
|
发表于 16-5-2006 01:45 AM
|
显示全部楼层
太棒了,super tomato,
果然是一箭双雕,
不只学到update after event,还学到
mc.onMouseMove = function() {
this._x += (_xmouse - this._x) * .1;
this._y += (_ymouse - this._y) * .1;
updateAfterEvent();
}
回复懃网友我已做了实验,
设为frameps12不是没有效果,是速度比较快一点,可能会做不到比较
如果不要加 updateAfterEvent();
再把frameps设高,例如60,就不会lagging,你应该明白为什么吧 |
|
|
|
|
|
|
|
发表于 16-5-2006 01:49 AM
|
显示全部楼层
super tomato,试了,可是好象有一点点不满意,mc并不能万全follow mouse,还有一段距离,
就是说不是startDrag,
是当鼠标移动时,mc会更着移动,可是当鼠标停下来,mc也会慢慢停,mc和鼠标之间会有一段距离,mc并不能万全在鼠标停下来时,也停在鼠标的位置 |
|
|
|
|
|
|
|

楼主 |
发表于 16-5-2006 01:50 PM
|
显示全部楼层
原帖由 yawchoong 于 16-5-2006 01:49 AM 发表
super tomato,试了,可是好象有一点点不满意,mc并不能万全follow mouse,还有一段距离,
就是说不是startDrag,
是当鼠标移动时,mc会更着移动,可是当鼠标停下来,mc也会慢慢停,mc和鼠标之间会有一段距离,mc ...
~_~ 代碼就表明了 onMouseMove 才會動﹐動的越慢方塊才能夠拉近距離﹐感覺就像是玩123木頭人的游戲一樣。當然你鼠標不動的時候它會動﹐你就該去看看醫生了~~~
改改一下就可以了啊﹐一樣用 framerate 2 測試看看
MovieClip.prototype.createRect = function(x:Number, y:Number, w:Number) {
with (this) {
lineStyle(1);
moveTo(x, y);
lineTo(x+w, y);
lineTo(x+w, y+w);
lineTo(x, y+w);
lineTo(x, y);
}
}
movePoint = function () {
mc._x += (_xmouse-mc._x)*.1;
mc._y += (_ymouse-mc._y)*.1;
updateAfterEvent();
}
this.createEmptyMovieClip('mc', this.getNextHighestDepth());
mc.createRect(0, 0, 20);
setInterval(movePoint, 50);
回懃 :
一般上的電腦在速度上都沒問題﹐如果某些使用者達不到要求的時候﹐updateAfterEvent不就可以幫你補救那種嚴重慢速度問題嗎?? |
|
|
|
|
|
|
|

楼主 |
发表于 16-5-2006 01:54 PM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|