2014-10-02 3 views
0

저는 Flash CC를 사용하여 HTML5 Canvas 게임을 만들고 있습니다. 그러나 두 개의 movieClip 사이에 hitTest를 만드는 방법을 알아낼 수 없습니다. EaselJS 웹에 일부 코드가 있지만 작동하지 않거나 작동 방식을 이해할 수 없습니다.플래시를 사용하는 HTML5 Canvas 게임의 HitTest

이 액션 패널에 내 코드입니다 :

this.addEventListener("tick",move.bind(this)); 
function move(){ 
    if (collision(this.bird, this.bar)){ 
    this.bird.play(5); 
    } 
} 
function collision(a,b) { 
    var locA = a.globalToLocal(100,0); 
    if (b.hitTest(locA.x, locA.y)) { 
    return true; 
    } 
} 
+0

실제 물체에 그러나 hitTest 시도 "A 히트가 있었다 ..!"; 어쨌든, 여기에 내가 생각 해낸거야 }' –

+0

Shucks는 HTML5에 대한 것임을 깨달았습니다. 나는 그럴 수 있는지 아닌지 잘 모릅니다. 그러나 특정 플래시 기능이 HTML5 변환에 없으면 놀랄 일이 아닙니다. –

+0

이 기능은 게임 개발에있어 보편적 인 기능이라고 생각합니다. –

답변

0

좋아, 그래서 나는 더 아직 플래시 또는 EaselJS이에 대한 기능 내장이없는 것 같아요, 그래서 나는이 함께했다 그것은 확인을 작동합니다. 그러나 모양의 실제 보이는 픽셀이 아닌 사각형 MovieClip 경계인 hitBox 만 검사합니다. HTML5 캔버스 용 Flash에서는 동영상 클립 인스턴스의 너비 및 높이가 지원되지 않으므로 속성 패널에서 해당 장면을 살펴 봐야합니다. 뿐만 아니라 (shapeA 그러나 hitTest (shapeB가)) {추적이 경우`좌표

var objA = this.bullet ; // The selected MovieClip 
var objA_width = 20; // enter selected Movieclip's width (you can't find out with script, duh!) 
var objA_height = 10; // enter selected Movieclip's height 

var objB = this.target; // The MovieClip to test collision with 
var objB_width = 100; // enter it's width 
var objB_height = 100; // ...and it's height 


this.addEventListener("tick",hitTest.bind(this)); 

function hitTest(){ 
    if (collision(objA, objB, objA_width,objA_height,objB_width,objB_height)){ 
    // code to run on collision; 
    } 
} 

var mca = new Object(); 
var mcb = new Object(); 

function collision(a,b,aWidth,aHeight,bWidth,bHeight) { 
    mca.xr = a.x + (aWidth/2); //the right edge of movieclip A 
    mca.xl = a.x - (aWidth/2); //the left edge of movieclip A 
    mca.yt = a.y - (aHeight/2); //the top edge of movieclip A 
    mca.yb = a.y + (aHeight/2); //the bottom edge of movieclip A 

    mcb.xr = b.x + (bWidth/2); 
    mcb.xl = b.x - (bWidth/2); 
    mcb.yt = b.y - (bHeight/2); 
    mcb.yb = b.y + (bHeight/2); 

    xHit = mca.xr > mcb.xl && mca.xl < mcb.xr; // returns true if the is any horisontal overlappnig 
    yHit = mca.yt < mcb.yb && mca.yb > mcb.yt; // returns true if the is any vertical overlapping 

    if (xHit && yHit){return true;} 
}