2014-07-05 2 views
1

배경 화면 활동의 배경에 이미지를 추가하려고합니다.AndEngine에서 배경의 배경 이미지를 설정할 수 없습니까?

menuBackgroundTexture = 새로운 BitmapTextureAtlas (getTextureManager(), 2 * CAMERA_WIDTH, 2 * CAMERA_HEIGHT, TextureOptions.DEFAULT :하지만 어떤 사람이 그것을 할 수있는 방법을 제안 할 수 있습니다, 그렇게 할 수없는 나는 여기에 내 코드입니다);

menuBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset (this.menuBackgroundTexture,this, "land.png", 0, 0);

는 THT 후 나는

this.menuBackgroundTexture.load()를 사용하여 시도; 하지만 작동하지 않습니다, 나는 또한 코드 SpriteBackground BG = 새로운 SpriteBackground 다음 시도 (새 스프라이트 (0, 0, menuBgTexture, this.getVertexBufferObjectManager()));

mScene.setBackground (bg);

이 또한 작동하지 않습니다. 제발 도와주세요.

+0

하나에 wallaper 활동에 대한 코드 아래 작업 큰 다음 안드로이드는 동시에 이미지를 표시하지 않는 동시에 오류를보고하지 않습니다. land.png 파일이 얼마나 큽니까? – SeahawksRdaBest

+0

는 771 킬로바이트를 @SeahawksRdaBest, 나는 또한 크기도 정확한지 확인하십시오. – Rahul

+0

작은 이미지를 사용하여 테스트 해 보셨습니까? – SeahawksRdaBest

답변

0

나는 마침내 그것을하는 방법을 발견했다. 여기서 동일한위한 코드이다

최종 BitmapTexture backgroundTexture = 새로운 BitmapTexture (this.getTextureManager()를 새로 IInputStreamOpener는() { @Override 공공의 InputStream 열기() {

  return getAssets().open("gfx/background1.jpg"); 
     } 
    }); 
    backgroundTexture.load(); 
    backgroundTextureRegion = TextureRegionFactory.extractFromTexture(backgroundTexture); final 
공개 IOException

배경 스프라이트 = 새로운 스프라이트 (CAMERA_WIDTH/2F - backgroundTextureRegion.getWidth()/2F, CAMERA_HEIGHT/2F - backgroundTextureRegion.getHeight()/2F, backgroundTextureRegion, this.getVertexBufferObjectMana ger()); mScene.attachChild (background);

다른 사람들에게 도움이되기를 바랍니다. 사용하려는 이미지 파일이 너무 경우

0

@Rahul도 내 배경 화면 서비스

public class MagicWallpaper extends BaseLiveWallpaperService { 

private TextureRegion region; 

@Override 
public EngineOptions onCreateEngineOptions() { 
    calculateWidthAndHeight(); 
    Camera mCamera = new Camera(0, 0, Helper.GAME_WIDTH, Helper.GAME_HEIGHT); 
    EngineOptions engOptions = new EngineOptions(true, 
      ScreenOrientation.PORTRAIT_FIXED, new FillResolutionPolicy(), 
      mCamera); 
    return engOptions; 
} 

@SuppressWarnings("deprecation") 
private void calculateWidthAndHeight() { 
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) 
      .getDefaultDisplay(); 
    Helper.GAME_WIDTH = display.getWidth(); 
    Helper.GAME_HEIGHT = display.getHeight(); 
} 

@Override 
public void onCreateResources(
     OnCreateResourcesCallback pOnCreateResourcesCallback) 
     throws Exception { 

    BitmapTextureAtlas atlas = new BitmapTextureAtlas(getTextureManager(), 
      600, 1024); 
    region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(atlas, 
      this, "wall.png", 0, 0); 
    atlas.load(); 
    pOnCreateResourcesCallback.onCreateResourcesFinished(); 
} 

@Override 
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) 
     throws Exception { 
    mEngine.registerUpdateHandler(new FPSLogger()); 
    Scene dScene = new Scene(); 
    dScene.setBackground(new SpriteBackground(new Sprite(0, 0, region, 
      getVertexBufferObjectManager()))); 
    pOnCreateSceneCallback.onCreateSceneFinished(dScene); 
} 

@Override 
public void onPopulateScene(Scene pScene, 
     OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception { 
    pOnPopulateSceneCallback.onPopulateSceneFinished(); 
} 

} 내가했다 알아 냈어 정말 짜증나는 일의

관련 문제