问题
Hi I am new to andengine and trying to code a basic sidescroller game using the ParallaxLayer class witch I got from the following example :http://www.andengine.org/forums/features/parallaxlayer-t5390.html I followed the example and it works.
My question is how would I display for example 3 images(Sun_Stage.png, Moon_Stage.png Dark_stage.png) in sequential manner as a scrollable background... First scroll until Sun_stage.png is finnished and then scroll the next stage witch is Moon_Stage.png?
The Player would start in the Sun_Stage while he walks the parallaxlayer would scroll the image.... when the Sun_Stage is finished(reached its end width) then the next Stage Moon_Stage should be visible and scroll?
Hope I make sense? I don't know if there's another way of doing this... I basically just want to code a sidescroller game that's never ending with scrollable background that changes.
Any help would be appreciated.
回答1:
Entity parent = new Entity();
attachChild(parent);
Sprite mountainsSprite = new Sprite(0, 0, WIDTH, HEIGHT, mountainsTextureRegion, mEngine.getVertexBufferObjectManager());
mountainsSprite.setPosition(0, 0);
parent.attachChild(mountainsSprite);
Sprite starsSprite = new Sprite(0, 0, WIDTH, HEIGHT, starsTextureRegion, mEngine.getVertexBufferObjectManager());
starsSprite.setPosition(mountainsSprite.getX()+ mountainsSprite.getWidth(), 0);
parent.attachChild(starsSprite);
ParallaxLayer parallaxLayer = new ParallaxLayer(camera, true, 4000);
backgroundParallax.setParallaxChangePerSecond(8);
backgroundParallax.setParallaxScrollFactor(1);
backgroundParallax.attachParallaxEntity(new ParallaxEntity(10, parent, true));
Here what i have done is added the required sprites to move in sequence to an entity.Then I made this entity as parallaxEntity to Parallax background
回答2:
The Rama's answer worked but...
I had to remove last parameter from the ParallaxEntity
constructor, set position and dimensions of the Entity
and avoid attaching the Entity
to the Scene
.
The resulting code looks like this:
Entity parent = new Entity(0, 0, mountainsWidth + starsWidth, height);
// create mountains
Sprite mountainsSprite = new Sprite(0, 0, WIDTH, HEIGHT, mountainsTextureRegion, mEngine.getVertexBufferObjectManager());
parent.attachChild(mountainsSprite);
// create stars
Sprite starsSprite = new Sprite(0, 0, WIDTH, HEIGHT, starsTextureRegion, mEngine.getVertexBufferObjectManager());
parent.attachChild(starsSprite);
// create parallax background
backgroundParallax.setParallaxChangePerSecond(8);
backgroundParallax.setParallaxScrollFactor(1);
backgroundParallax.attachParallaxEntity(new ParallaxEntity(10, parent));
来源:https://stackoverflow.com/questions/22454116/parallaxlayer-with-multiple-images-entities-scrolling-in-sequential-manner