車子的移動 |
| 作者:佚名 来源:闪吧 更新:2007-1-13 20:48:59 错误报告 我要投稿 |
UploadFile/2004-4/2004424155107.swf
因為在這裡都只看到效果的例子, 所以在這裡教大家個車子的移動技術...
當然要用在什麼地方就看你們自己的發揮了...;p
1.首先當然是畫出一輛車子并定義其實體名字為car

2.在應該加入以下代碼
max = 10; speed = 0;
onEnterFrame = function() { with(car) { posX = Math.cos (angle); //這裡的圓的計算可以參考flash8的教學 posY = Math.sin (angle); if (Key.isDown(key.left) && speed != 0) degree -= 5; //按左鍵角度-5 if (Key.isDown(key.right) && speed != 0)degree += 5; if (Key.isDown(key.up) && speed < max) speed += 0.8; //按向上鍵速度增加 if (Key.isDown(key.down) && speed > -max) speed -= 0.4; //因為退車速度會比較慢 _x += posX * speed; //設定車子的x和y, 當然重要的步驟是以上的posX和posY, 還有下方的弧度計算 _y += posY * speed; _rotation = degree; if ( speed > 0 ) speed -= 0.25; if ( speed < 0 ) speed += 0.25; angle = (degree*(Math.PI/180)); } }
3. 進行測試
点击浏览该文件
實例 : http://www.tokidoki.it/
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |