Skip to main content

Posts

Showing posts from May, 2006

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 (…