[英]how to make life movie clip using actionscript 2.0
我正在為我的項目使用ActionScript 2.0。 我有一個沿x軸移動的影片剪輯。 我的問題是,如果該影片剪輯到達給定的邊界,它應該自動扣除一個生命。 我的代碼不起作用。
這是時間軸的代碼:
var life:Number = 5; lives = 3; boundary = 280; var speed:Number = 1; var boundary:Number = 280; this.onEnterFrame = function():Void { if (clip._x > boundary) { clip._x -= speed; } else { clip._x = boundary; delete this.onEnterFrame; } } if(lives == 0){ gotoandstop(132); }
這是我移動MC的代碼:
onClipEvent (load) { speed = 1; boundary = 280; } onClipEvent (enterFrame) { if (this._x > boundary) { this._x -= speed; } else { this._x = boundary; this._visible = false; life -= 1; lifebox.text = life.toString(); } }
主時間軸代碼還可以。
錯誤在於引用。 這是正確的MovieClip代碼。
onClipEvent (load) { speed = 1; boundary = 280; } onClipEvent (enterFrame) { if (this._x > boundary) { this._x -= speed; } else { this._x = boundary; this._visible = false; // use parent to refer variables and textfields declared, level up (in this case to main timeline); _parent.life -= 1; _parent.lifebox.text = _parent.life; } }
首先,您不需要時間軸代碼和影片剪輯代碼。
另一方面,如果您希望影片剪輯消失,則應將其刪除或放在其他位置,因為hitTest將連續運行。
主要時間軸代碼
var lifes:Number = 5;
var speed:Number = 1;
var boundary:Number = 280;
var startX:Number = 320;
clip._x = startX;
this.onEnterFrame = function():Void {
if (clip._x > boundary) {
clip._x -= speed;
} else {
lifes--;
clip._x = startX;
if (lifes == 0) {
gotoAndStop(132);
delete this.onEnterFrame;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.