as3 box2d 포트로 phsyics를 구현하려고합니다. 나는 현재 게임에서 특정 스프라이트에 대해 각각 b2body를 가지고 있으며 스프라이트의 위치를 몸 위치에서 올바르게 업데이트 할 수 있습니다. 이 아래 그림에 표시됩니다 (debugDraw는 해당 spirtes에 입혔다 b2bodies의 위치를 보여줍니다. 녹색 사각형은 벽과 바닥이다) 나는 또한 스프라이트의 회전이 반영 갖고 싶어,올바른 오프셋을 찾아서 회전 후 box2D 본문의 위치에 스프라이트를 조정하는 방법
그러나 b2bodies의 회전. 하지만, 스프라이트를 회전 한 후에, b2body 위치로 정확하게 중심을 맞추기 위해 사용하는 오프셋은 더 이상 정확하지 않습니다.
다음과 같이 스프라이트의 위치를 업데이트하는 내 코드입니다 : 내가 올바른 X와 Y가 스프라이트를 회전 한 후 좌표 시스템 (플래시와 Box2D의) 사이의 오프셋을 찾을 수있는 방법
private function Update(update_event:TimerEvent):void
{
//step physics simulation forward
world.Step(0.025,10,10);
//update all objects in world
for each (var obj:HouseItemPhysicsObject in physicsObjects)
{
//update object's position from gravity if it is not being dragged
if(!obj.isHeld)
{
/*adjust rotation of sprite along with body -> yourMC.rotation = (yourMCbody.GetAngle() * 180/Math.PI) % 360; */
obj.object.rotation = (obj.pBody.GetAngle() * 180/Math.PI) % 360;
if(obj.object.rotation >=5)
// set object's x position but adjust for offset between the cooridinate systems
obj.x = (obj.pBody.GetPosition().x* scaleFactor)-(obj.object.width/2);
//keep in horizontal bounds of screen
if(obj.x > GeneralConstants.GAME_WIDTH)
{
obj.x =GeneralConstants.GAME_WIDTH;
}
else if(obj.x < 0)
{
obj.x = 0;
}
// set object's x position but adjust for offset between the cooridinate systems in Flash and box2d
obj.y = (obj.pBody.GetPosition().y * scaleFactor)-(obj.object.height/2);
//keep in vertical bounds of the screen
if(obj.y > GeneralConstants.GAME_HEIGHT)
{
obj.y =GeneralConstants.GAME_HEIGHT;
}
else if(obj.x < 0)
{
obj.x = 0;
}
/*Draw shapes to see for debug*/
//obj.DrawDebug();
//trace("OBJECT's X is :" + obj.x + " Y is :" +obj.y);
trace("Object's rotation is:" + obj.object.rotation);
}
}
//move debug draw to front of display list
m_sprite.parent.setChildIndex(m_sprite, m_sprite.parent.numChildren - 5);
world.DrawDebugData();
}
을 b2Body에 따르면? 도와 주셔서 감사합니다.
EDIT : 명확성을 위해 은 개체 Sprite 클래스를 확장하는 클래스이며, 데이터 부재 _object는 영화 클립의 인스턴스이다. 당신이 물리적 객체의 당신의 스프라이트 속성을 부여 할 경우
아니에요 익숙한 당신이 위치를 업데이트 할 때
, 단순히 회전에 의해 오프셋 회전에 추가 그리고 저는 연구를 할 수있는 위치에 있지 않습니다 : 그러나 Sprite를 b2body에게 아이처럼 붙일 수있는 능력이 있습니까? 그렇다면 추가하고 잊어 버리십시오. – Vesper
그 시점에서'(obj.pBody.GetAngle() * 180/Math.PI) % 360' 값은 무엇입니까? 음수 값을 반환합니까? – bosnjak