2013-10-10 2 views
1

저는 AndEngine에서 연습하고 있습니다. 배경과 스프라이트를 만들고 모션과 중력을 추가했습니다.AndEngine 배경 음악 오류

그래서 배경 음악과 소리로 약간 연습하기로 결정했지만 문제가 있습니다. 이제 응용 프로그램을 시작할 때 검정색 화면이 나타나고 스프라이트가 왜곡되고 물론 음악이 들리지 않습니다.

도와 주시겠습니까? 다음 코드입니다.

public class MainActivity extends BaseGameActivity { 
    Scene scene; 
    private Music music; 
    protected static final int CAMERA_WIDTH = 850; 
    protected static final int CAMERA_HEIGHT = 480; 
    BitmapTextureAtlas playerTexture; 
    ITextureRegion playerTexureRegion; 
    PhysicsWorld physicsWorld; 



    @Override 
    public EngineOptions onCreateEngineOptions() { 
     // TODO Auto-generated method stub 

     Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); 

     EngineOptions options = new EngineOptions(true, 
       ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), mCamera); 
     return options; 
    } 

    @Override 
    public void onCreateResources(
      OnCreateResourcesCallback pOnCreateResourcesCallback) 
      throws Exception { 
     // TODO Auto-generated method stub 


     loadGfx(); 
     loadSounds(); 

     // resource 
     pOnCreateResourcesCallback.onCreateResourcesFinished(); 
    } 
    private void loadSounds() { 
     // TODO Auto-generated method stub 
     try 
     { 
      music = MusicFactory.createMusicFromAsset(mEngine.getMusicManager(), this,"mfx/oldf.ogg"); 
     } 
     catch (IOException e) 
     { 
      e.printStackTrace(); 
     } 

    } 

    private void loadGfx() { 
     // TODO Auto-generated method stub 
     BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); 
     // width and height power of 2^x 
     playerTexture = new BitmapTextureAtlas(getTextureManager(), 64, 64); 
     playerTexureRegion = BitmapTextureAtlasTextureRegionFactory 
       .createFromAsset(playerTexture, this, "player.png", 0, 0); 
     playerTexture.load(); 

    } 
    @Override 
    public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) 
      throws Exception { 
     this.scene = new Scene(); 
     this.scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f)); 
     this.music.play(); 
     physicsWorld = new PhysicsWorld(new com.badlogic.gdx.math.Vector2(0, SensorManager.GRAVITY_EARTH), false); 
     this.scene.registerUpdateHandler(physicsWorld); 
     createWalls(); 

     pOnCreateSceneCallback.onCreateSceneFinished(this.scene); 

    } 

    private void createWalls() { 
     // TODO Auto-generated method stub 
     FixtureDef WALL_FIX = PhysicsFactory.createFixtureDef(0.0f, 1.0f, 0.0f); 
     Rectangle ground = new Rectangle(0, CAMERA_HEIGHT - 15, CAMERA_WIDTH, 
       15, this.mEngine.getVertexBufferObjectManager()); 
     ground.setColor(new Color(15, 50, 0)); 
     PhysicsFactory.createBoxBody(physicsWorld, ground, BodyType.StaticBody, 
       WALL_FIX); 
     this.scene.attachChild(ground); 
    } 


    @Override 
    public void onPopulateScene(Scene pScene, 
      OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception { 
     // TODO Auto-generated method stub 

     Sprite sPlayer = new Sprite(CAMERA_WIDTH/2, CAMERA_HEIGHT/2, 
       playerTexureRegion, this.mEngine.getVertexBufferObjectManager()); 
     sPlayer.setRotation(45.0f); 
     final FixtureDef PLAYER_FIX = PhysicsFactory.createFixtureDef(10.0f, 
       1.0f, 0.0f); 
     Body body = PhysicsFactory.createCircleBody(physicsWorld, sPlayer, 
       BodyType.DynamicBody, PLAYER_FIX); 
     this.scene.attachChild(sPlayer); 
     physicsWorld.registerPhysicsConnector(new PhysicsConnector(sPlayer, 
       body, true, false)); 

     pOnPopulateSceneCallback.onPopulateSceneFinished(); 
    } 

고마워요!


UPDATE

로그 캣 : 지금 문제를 알고

10-09 21:07:46.635: E/AndEngine(5305): MainActivity.onCreateGame failed. @(Thread: 'GLThread 4852') 
10-09 21:07:46.635: E/AndEngine(5305): java.lang.IllegalStateException: To enable the MusicManager, check the EngineOptions! 
10-09 21:07:46.635: E/AndEngine(5305): at org.andengine.engine.Engine.getMusicManager(Engine.java:294) 
10-09 21:07:46.635: E/AndEngine(5305): at com.example.prueba2.MainActivity.loadmusic(MainActivity.java:73) 
10-09 21:07:46.635: E/AndEngine(5305): at com.example.prueba2.MainActivity.onCreateResources(MainActivity.java:62) 
10-09 21:07:46.635: E/AndEngine(5305): at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181) 
10-09 21:07:46.635: E/AndEngine(5305): at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110) 
10-09 21:07:46.635: E/AndEngine(5305): at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80) 
10-09 21:07:46.635: E/AndEngine(5305): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1471) 
10-09 21:07:46.635: E/AndEngine(5305): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1241) 
+0

'mfx' 폴더가 저작물 디렉토리에 있습니까? – kabuto178

+0

@ kabuto178 예, 내 자산 디렉토리에 있습니다. 제가 잘못 놓았습니다. -loadSounds(); – Loreln

+0

이제 제대로 작동합니까? – kabuto178

답변

10

OOOoooo, 당신의 EngineOptions 클래스에이 추가

options.getAudioOptions().setNeedsMusic(true); 
    options.getAudioOptions().setNeedsSound(true); 

EngineOptions 당신이 표시해야합니다 시작하는 당신 당신의 씬에 사운드가 필요할 것입니다. EngineOptions 방법에 대해 약간의 감독 만합니다.

+2

당신은 괜찮아! 고마워 !!!, 그냥, 내 경우에는 -options.getAudioOptions()를 사용한다. setNeedMusic (true); – Loreln

+0

물론 도움이 되었기 때문에 기쁩니다. – kabuto178