나는 게임을 작성하고 있으며 적과 총알이 있습니다. 총알이 적과 충돌하면 적과 총을 파괴하고 싶습니다. 총알이 적을 맞았는지 테스트하려면 hitTestPoint()
메서드를 사용하고 있습니다.hitTestPoint()가 충돌을 정확하게 테스트하지 않습니다.
for each(var bullet:Bullet in this.bullets) {
for each(var enemy:Enemy in this.enemies) {
if(enemy.hitTestPoint(bullet.x, bullet.y)) {
trace("hit");
}
}
bullet.update();
}
this.bullets
및 this.enemies
는 글 머리 기호 및 원수에 대한 객체를 포함 모두 배열 인 : 여기 내 게임 루프의 코드입니다. -
package com {
import flash.display.MovieClip;
import flash.display.Stage;
public class Enemy extends MovieClip {
public var speed:Number = 4;
private var stageRef:Stage;
public function Enemy(stage:Stage) {
this.stageRef = stage;
this.x = this.stageRef.stageWidth/3;
this.y = this.stageRef.stageHeight/2;
}
public function update() {
}
}
}
문제는, x와 총알과 적군의 y 값 모두가 아니라, 동일한 경우 hitTestPoint
는 true를 돌려
package com {
import flash.display.MovieClip;
import flash.display.Stage;
public class Bullet extends MovieClip {
private var stageRef:Stage;
public var speed:Number = 10;
public function Bullet(stage:Stage) {
this.stageRef = stage;
}
public function update() {
this.x += Math.sin((Math.PI/180) * (360 - this.rotation)) * this.speed;
this.y += Math.cos((Math.PI/180) * (360 - this.rotation)) * this.speed;
}
}
}
: 여기에 두 종류의 두 무비 클립이 겹치는 경우보다 이로 인해 총알이 적을 통해 오른쪽으로 이동하지만 적중으로 등록되지 않습니다. 아마도 경계 상자가 누락 된 것입니까?
총알과 적의 좌표가 같을 때 총알이 적중하는 경우에만 hitTestPoint
을 되돌릴 수있는 방법이 있습니까?
감사합니다.
감사합니다. 그것이 아직도 조금 버그 인 것처럼 보이지만. 때로는 총알이 이동했을 때 적을 건너 뛰기 때문에 총알이 맞지 않는 경우가 있습니다. –
프레임 속도 일 수 있습니다. 총알이 프레임 사이의 오브젝트 위로 점프하면 놓칠 수 있습니다. – Sam