2014-12-24 3 views
2

필자는 Phaser를 처음 사용하고 특히 충돌로 스프라이트의 히트 박스 크기를 조정하는 데 문제가 있습니다. 이것은 모범 사례가 아닌 문제를 강조하기위한 약간의 인위적인 예입니다.바운딩 박스 크기 조정의 페이저 및 문제

아래 예제에서 볼 수 있듯이 저는 두 개의 스프라이트, 1 개의 문자 및 1 개의 적을 모두 경계 상자 (debug.spriteBounds (녹색 색조)와 함께 표시됨).

enter image description here

는 내가 그 짧은 시간 동안 칼과 파괴력을 가진 특정 일에 더 큰 하나에 플레이어의 스프라이트를 변경 공격합니다. 나 충돌이 나는 문제로 실행하는 부분 인 발생했습니다 확인하는

enter image description here

당신이 스프라이트 경계 상자는 크기가 조정 변경 될 때 볼 수 있듯이

, 그래서 모든 남아 있다는 것입니다. 당신이 경계가 커질 볼 수 있듯이

attacking 
_player.js:95 boundsBeforeAttack= c.Rectangle {x: 856.0833333333328, y: 737.0416666666679, width: 32, height: 32, offset: function…} 
_player.js:100 boundsduringattack= c.Rectangle {x: 828.3333333333328, y: 737.6944444444443, width: 87.5, height: 32, offset: function…} 
_player.js:101 touchingright= false 

는 그러나이 존중하지 않는 것 :

여기에 내 코드 여기

if (this.attackRight.justDown) { 
       console.log('attacking'); 
       console.log('boundsBeforeAttack=', this.player._bounds); 

       this.player.loadTexture('playerAttack', 0); 

       this.g.time.events.add(Phaser.Timer.SECOND * 0.5, function() { 
        console.log('boundsduringattack=', this.player._bounds); 
        console.log('touchingright=', this.player.body.touching.right); 
       }, this); 


       this.g.time.events.add(Phaser.Timer.SECOND * 3.25, function() { 
        this.player.loadTexture('player', 0); 
       }, this); 
      } 

다음과 같은 출력이입니다. 나는 진실이되기 위해 만지고 싶다.

다른 시도는 player.body.reset(); 똑같은 일을하는 physics.arcade.collide 및 overlay 메소드를 사용하여 아무 것도하지 않는 것처럼 보입니다.

+0

나는 또한 이와 같은 충돌 탐지를 시도했다. 정확히 같은 효과가있다. this.g.game.physics.arcade.collide (this.player, this.g.enemy.sprite, function() { console.log ('hit!'); }); 현재 터치하는 것을 사용하는 이유는 터치가 어느 쪽에서 발생했는지 알 필요가 있기 때문입니다. – Jamesla

+0

작동 여부는 확실하지만 중복으로 시도 했습니까? http://phaser.io/docs/Phaser.Physics.Arcade.html/Phaser.Physics.Arcade.html#overlap –

답변

1

body.touchingarcade.collide 또는 arcade.overlap을 먼저 호출하여 업데이트됩니다. 기본 사항은 http://phaser.io/examples/v2/arcade-physics/one-way-collision을 참조하십시오 (단방향 부분 무시).

스프라이트 물리학 자에게 debug.body (debug.spriteBounds 대신)을 사용하십시오.

관련 문제