Skip to main content

Smooth movement --- JUMP ACTION


這個教學是上一篇 Smooth movement in FL1.1的加強版,並加入了跳躍動作。在FL1.1中是沒有所謂的hitTest(),所以這邊利用了一個方法來達到簡易的碰撞測試,讓火柴人可以跳到移動平台上:

取得跳躍平台的方塊四頂點的座標,與跳躍 MC作座標檢測


call hitTest: (mc = main control movieclip's name)
W =hitTestTarget._width/2;
xMin = hitTestTarget._x-W;
xMax = hitTestTarget._x+W;
H =hitTestTarget._height/2;
yMin =hitTestTarget._y-H;
yMax = hitTestTarget._y+H;
if (mc._x>xMin && mc._x < xMax) {
if (mc._y>yMin && mc._y < yMax) {
hitTarget =hitTestTarget;
trace(hitTarget add " be hit");
mc._y = yMin;
}
}


Key controler :
on (keyPress "") {
hitTarget = "";
if (!jump_co.jump) {
trace("跳躍開始");
jump_co.ymov = -21;
jump_co.jump = true;
jump_co.status = "jump";
tellTarget ("mc") {
gotoAndStop("jump");
}
}
}


Jump controler 跳躍控制器(jump_co):
if (jump) {
ymov += 3;
if (status eq "stand") {
//在hitTest中,如果確定碰撞到平台,status會設定為stand
jump = false;
tellTarget (__target) {
gotoAndStop("stand");
}
} else {
//drop
eval(__target)._y += ymov;
if (ymov>0) {
status = "drop";
call("/:hitTest");
}
}
}


[下載原始檔]

Comments

Popular posts from this blog

[書評] 拖延心理學:為什麼我老是愛拖延?是與生俱來的壞習慣,還是身不由己?

作者: Jane B. Burka & Lenora M . Yuen 推薦指數 ★★★★★ 有時候,只是想了解事情發生原因而不是尋求解法 在這邊不是要講這本書的內容,而是想聊它對我的影響。