2012-05-29 4 views
1

Я пытаюсь создать фон для своей игры, создающий впечатление, что некоторые вещи более чем другие. так скажет, что у меня есть небо, солнце, облака и земля. небо и солнце самые дальние, облака посередине и земля впереди. теперь, если игрок увеличивает или кадрирует камеру, я хочу, чтобы дальнейшие слои двигались меньше, чем более близкие слои, чтобы создать впечатление, что они действительно больше (земля движется больше всего, а облака меньше движутся, а солнце почти не двигается) так же, как и способ автоматического параллакса, за исключением того, что он является статическим фоном, поэтому обычно ничего не движется, если игроки не увеличивают или уменьшают масштаб.фон с несколькими слоями (например, параллакс)

эта концепция реализована в сердитых птицах с игровыми предметами (птицами, свиньями, блоками ...), а земля находится впереди, горный слой посередине, а небо и облака - самые дальние.

Теперь, если вы поняли, что я пытаюсь выполнить, пожалуйста, дайте мне представление, как это сделать, потому что это заставило меня сходить с ума в последние несколько дней, и я просто не мог даже поставить концепцию для ее реализации. любой код также будет отличным.

ответ

9

Вы можете попробовать использовать AndEngine для такой цели:
http://www.youtube.com/watch?v=ug5vfys6MIA

также смотрите: http://www.andengine.org/forums/features/parallaxlayer-t5390.html

Это очень легко добиться эффекта, как это, вот пример:

@Override 
    public void onLoadResources() { 
     BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); 

     this.mBitmapTextureAtlas = new BitmapTextureAtlas(256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA); 
     this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "player.png", 0, 0, 3, 4); 
     this.mEnemyTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "enemy.png", 73, 0, 3, 4); 

     this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.DEFAULT); 
     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.mEngine.getTextureManager().loadTextures(this.mBitmapTextureAtlas, this.mAutoParallaxBackgroundTexture); 
    } 

    @Override 
    public Scene onLoadScene() { 
     this.mEngine.registerUpdateHandler(new FPSLogger()); 

     final Scene scene = new Scene(); 
     final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5); 
     autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerBack.getHeight(), this.mParallaxLayerBack))); 
     autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, this.mParallaxLayerMid))); 
     autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerFront.getHeight(), this.mParallaxLayerFront))); 
     scene.setBackground(autoParallaxBackground); 

     /* 
     * Calculate the coordinates for the face, so its centered on the camera. 
     */ 
     final int playerX = (CAMERA_WIDTH - this.mPlayerTextureRegion.getTileWidth())/2; 
     final int playerY = CAMERA_HEIGHT - this.mPlayerTextureRegion.getTileHeight() - 5; 

     /* Create two sprits and add it to the scene. */ 
     final AnimatedSprite player = new AnimatedSprite(playerX, playerY, this.mPlayerTextureRegion); 
     player.setScaleCenterY(this.mPlayerTextureRegion.getTileHeight()); 
     player.setScale(2); 
     player.animate(new long[] { 200, 200, 200 }, 3, 5, true); 

     final AnimatedSprite enemy = new AnimatedSprite(playerX - 80, playerY, this.mEnemyTextureRegion); 
     enemy.setScaleCenterY(this.mEnemyTextureRegion.getTileHeight()); 
     enemy.setScale(2); 
     enemy.animate(new long[] { 200, 200, 200 }, 3, 5, true); 

     scene.attachChild(player); 
     scene.attachChild(enemy); 

     return scene; 
    } 
+0

спасибо за ответ, что у него хорошее видео, но как это сделать, это то, что мне нужно. – Ayham

+0

, кстати, я уже использую andengine – Ayham

+0

отредактированный пост ;-) – Thkru

Смежные вопросы