2013-08-28 3 views
0

그래서 jme3 엔진과 SDK를 사용하는 방법을 배웠습니다. 필자는 SimpleApplication을 확장하여 기본 응용 프로그램 파일 외부에서 작업하는 것으로 시작하여 내 응용 프로그램의 objet-orient을 더욱 자세하게 설명했습니다.SimpleApplication 외부의 물리 상태를 올바르게 초기화하는 중

내 질문은 .. 어떻게 물리 개체를 올바르게 초기화합니까? 마찬가지로 .. phyiscs라는 BulletAppState 객체가 있지만 처음에 값이 할당되지 않은 Player 클래스를 만듭니다! 생성자 내에 할당됩니다.

class Player { 
    BulletAppState physics; 

    public Player(BulletAppState physicsState) { 
      this.physics = physicsState; // State should now be initialized when 
             // this constructor is is called 
    } 
} 

그런 다음, 메인 클래스 파일

class Main extends SimpleApplcation { 

    Player player; 
    BulletAppState physics; 

    public static void main(String[] args) { 
      Main app = new Main(); 
      app.start(); 
    } 

    @Override 
    public void simpleInitApp() { 
      physics = new BulletAppState(); 
      physics.setThreadingType(BulletAppState.ThreadingType.PARALLEL); 
      stateManager.attach(physics); 

      player = new Player(); 
    } 
} 

에서 내가 기대 원하는 결과를 얻을 수 없습니다.

출력 결과는 다음과 같습니다.

기본 클래스 물리 상태가 활성화 되었습니까? True

플레이어 등급 물리 상태가 활성화 되었습니까? False

답변

0

Player() 생성자에 physics을 전달하여 BulletAppState과 같이 초기화하면됩니다.

player = new Player(physics); 
+0

죄송합니다. 제 입력란에 오타가있었습니다. 생성자에서 물리 객체를 전달하고있었습니다. 하지만 physics.isEnabled(); 거짓을 반환합니다. – user2723909

0

큰 힌트 : stateManager.attach()가 대기열에 항목을 추가합니다!

simpleInitApp 호출시 초기화 유일한 appStates

그 내가있어 new Main(appStates...)

에서 생성자에 전달하는이 내 객체 지향 게임 프로젝트에서 잘 작동 :

Main app = new Main(new StatsAppState(), new FlyCamAppState(), new DebugKeysAppState(), physics);

그리고 simpleInitApp() 호출에서 모든 객체에 멋지게 전달됩니다.