움직이는 스프라이트로 일정한 배경 이미지를 만들고 싶습니다. andengine
, 아래 코드를 사용했지만 충돌합니다. 제발 도와주세요.움직이는 스프라이트를 사용하여 x 축 방향으로 일정한 배경 이미지를 만드는 방법
public VertexBufferObjectManager vbom;
private void createBackground() {
ParallaxBackground background = new ParallaxBackground(0, 0, 0);
background.attachParallaxEntity(new ParallaxEntity(0, new Sprite(0, 0, background_region, vbom)));
scene.setBackground(background);
}
private void loadGameGraphics() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/game/");
gameTextureAtlas = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
background_region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTextureAtlas, activity, "background.png");
}
로그 고양이
gamescene.java에서02-18 04:38:16.370: E/AndEngine(1246): org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder$TextureAtlasBuilderException: Could not build: 'AssetBitmapTextureAtlasSource(gfx/game/background.png)' into: 'BitmapTextureAtlas'.
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder.build(BlackPawnTextureAtlasBuilder.java:88)
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.opengl.texture.atlas.buildable.BuildableTextureAtlas.build(BuildableTextureAtlas.java:241)
02-18 04:38:16.370: E/AndEngine(1246): at com.game.manager.ResourcesManager.loadGameGraphics(ResourcesManager.java:199)
02-18 04:38:16.370: E/AndEngine(1246): at com.game.manager.ResourcesManager.loadGameResources(ResourcesManager.java:113)
02-18 04:38:16.370: E/AndEngine(1246): at com.game.manager.SceneManager$1.onTimePassed(SceneManager.java:128)
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.engine.handler.timer.TimerHandler.onUpdate(TimerHandler.java:94)
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.engine.handler.UpdateHandlerList.onUpdate(UpdateHandlerList.java:47)
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.engine.Engine.onUpdateUpdateHandlers(Engine.java:618)
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.engine.Engine.onUpdate(Engine.java:605)
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.engine.LimitedFPSEngine.onUpdate(LimitedFPSEngine.java:52)
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.engine.Engine.onTickUpdate(Engine.java:568)
02-18 04:38:16.370: E/AndEngine(1246): at org.andengine.engine.Engine$UpdateThread.run(Engine.java:858)
02-18 04:38:16.390: W/dalvikvm(1246): threadid=13: thread exiting with uncaught exception (group=0xb1a35ba8)
02-18 04:38:16.410: E/AndroidRuntime(1246): FATAL EXCEPTION: UpdateThread
02-18 04:38:16.410: E/AndroidRuntime(1246): Process: com.game, PID: 1246
02-18 04:38:16.410: E/AndroidRuntime(1246): java.lang.NullPointerException
02-18 04:38:16.410: E/AndroidRuntime(1246): at org.andengine.entity.sprite.Sprite.<init>(Sprite.java:62)
02-18 04:38:16.410: E/AndroidRuntime(1246): at com.game.scene.GameScene.createBackground(GameScene.java:809)
02-18 04:38:16.410: E/AndroidRuntime(1246): at org.andengine.engine.Engine.onUpdate(Engine.java:605)
02-18 04:38:16.410: E/AndroidRuntime(1246): at org.andengine.engine.LimitedFPSEngine.onUpdate(LimitedFPSEngine.java:52)
02-18 04:38:16.410: E/AndroidRuntime(1246): at org.andengine.engine.Engine.onTickUpdate(Engine.java:568)
02-18 04:38:16.410: E/AndroidRuntime(1246): at org.andengine.engine.Engine$UpdateThread.run(Engine.java:858)
02-18 04:38:16.520: D/AndEngine(1246): GameActivity.onPause @(Thread: 'main')
,
개인 무효 loadGameGraphics() {resources.java
개인 장면 createBackground에서
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/game/");
mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(activity.getTextureManager(), 1024, 1024,TextureOptions.BILINEAR);
mParallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mAutoParallaxBackgroundTexture, activity, "parallax_background_layer_front.png", 0, 0);
mParallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset( mAutoParallaxBackgroundTexture, activity, "parallax_background_layer_back.png", 0, 188);
mParallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mAutoParallaxBackgroundTexture, activity, "parallax_background_layer_mid.png", 0, 669);
}
() {
resourcesManager.mAutoParallaxBackgroundTexture.load();
final Scene scene = new Scene();
final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
int CAMERA_HEIGHT = 480;
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - resourcesManager.mParallaxLayerBack.getHeight(), resourcesManager.mParallaxLayerBack,vbom)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, resourcesManager.mParallaxLayerMid, vbom)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, CAMERA_HEIGHT - resourcesManager.mParallaxLayerFront.getHeight(), resourcesManager.mParallaxLayerFront, vbom)));
scene.setBackground(autoParallaxBackground);
반환 장면;
}
스택 트레이스
5월 2일에서 19일까지 : 01 : 55.710 (1083) AndEngine/W : 01 : 55.710 ParallaxEntity의 OffsetCenterXposition은 0 5월 2일부터 19일까지 될 것으로 예상된다 : W/AndEngine (1083) : ParallaxEntity의 OffsetCenterXposition은 0 일 것으로 예상됩니다. 02-19 05 : 01 : 55.710 : W/AndEngine (1083) : ParallaxEntity의 OffsetCenterXposition은 0 일 것으로 예상됩니다.
public GameActivity 클래스는 BaseGameActivity를 확장합니다. {
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
private BoundCamera camera;
private ITexture parallax_background;
private Music music;
private ITextureRegion background_region;
private BitmapTextureAtlas mAutoParallaxBackgroundTexture;
private BuildableBitmapTextureAtlas al;
private BitmapTextureAtlas background;
public ITextureRegion mParallaxLayerFront;
public ITextureRegion mParallaxLayerBack;
public ITextureRegion mParallaxLayerMid;
private Player player;
@Override
public Engine onCreateEngine(EngineOptions pEngineOptions)
{
return new LimitedFPSEngine(pEngineOptions, 60);
}
public EngineOptions onCreateEngineOptions()
{
camera = new BoundCamera(0, 0, 800, 480);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), this.camera);
engineOptions.getAudioOptions().setNeedsMusic(true).setNeedsSound(true);
//engineOptions.getRenderOptions().getConfigChooserOptions().setRequestedMultiSampling(true);
engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
return engineOptions;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
SceneManager.getInstance().getCurrentScene().onBackKeyPressed();
}
return false;
}
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException
{
MusicFactory.setAssetBasePath("mfx/");
try {
music = MusicFactory.createMusicFromAsset(mEngine
.getMusicManager(), this, "abcd.wav");
music.setLooping(true);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/game");
this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(this.getTextureManager(), 2048, 2048,TextureOptions.BILINEAR);
this.mParallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_front.png", 0, 0);
this.mParallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_back.png", 0, 188);
this.mParallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_mid.png", 0, 669);
this.mAutoParallaxBackgroundTexture.load();
ResourcesManager.prepareManager(mEngine, this, camera, getVertexBufferObjectManager());
//mEngine.getTextureManager().loadTexture(mAutoParallaxBackgroundTexture);
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException
{
music.play();
SceneManager.getInstance().createSplashScene(pOnCreateSceneCallback);
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerBack.getHeight(), this.mParallaxLayerBack, vertexBufferObjectManager)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, this.mParallaxLayerMid, vertexBufferObjectManager)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerFront.getHeight(), this.mParallaxLayerFront, vertexBufferObjectManager)));
scene.setBackground(autoParallaxBackground);
scene.attachChild(player);
return;
}
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws IOException
{
mEngine.registerUpdateHandler(new TimerHandler(2f, new ITimerCallback()
{
public void onTimePassed(final TimerHandler pTimerHandler)
{
mEngine.unregisterUpdateHandler(pTimerHandler);
SceneManager.getInstance().createMenuScene();
}
}));
pOnPopulateSceneCallback.onPopulateSceneFinished();
}
@Override
protected void onDestroy()
{
super.onDestroy();
System.exit(0);
}
}
크래시가 발생하고 게시 한 코드가 오류 인 경우 씬이 null임을 나타냅니다. 그래도 충돌의 스택 추적을 게시해야합니다. – Blackbelt
답장을 보내 주셔서 감사합니다. stacktrace를 추가했습니다. – shaffz
저에게 vbom이 null 인 것 같습니다 – Blackbelt