[Update] ParallaxLayer

  ... the case you feel the need for a new feature or want to submit one.

Re: Scrollable Parallax Background

Postby ill2005 » Mon Jan 09, 2012 7:00 am

I haven't had the time to look over your code yet (and I may not in the near future), but looking at the pictures makes me think it may be a problem with the autoparalax rather than the black line issue.

If you look at your second screenshot, your arrow shows a gap between the end and the beginning of the paralax layer. You can see that it's a gap because (since we made the bg transparent) the gap is the same color as the layer behind it. I would look into the paralax code and see if it adds a border or padding or anything that may have caused the issue. I'd also try to double check your sizing to make sure you arent a few digits off anywhere.

Hope this helps!
ill2005
 
Posts: 22
Joined: Thu Sep 08, 2011 2:04 am

Re: Scrollable Parallax Background

Postby stormtroopa » Tue Jan 17, 2012 11:20 pm

I have another remark to your code (not because of the artifact).

The code can be indeed much simpler. The pSecondsElapsed argument is of no interest at all (at least I don't see y).
Also , there is no need to calculate the parallaxValue on each onUpdate().
Thanks anyway for the code.
In case you are interested in my implementation:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ScrollableParallaxBackground extends ParallaxBackground {
  2.  
  3.         private float cameraPreviousX;
  4.         private float cameraOffsetX;
  5.  
  6.         private Camera camera;
  7.  
  8.         public ScrollableParallaxBackground(final float pRed, final float pGreen,
  9.                         final float pBlue, Camera camera) {
  10.                 super(pRed, pGreen, pBlue);
  11.  
  12.                 this.camera = camera;
  13.                 cameraPreviousX = camera.getMinX();
  14.                 this.mParallaxValue = -this.camera.getMinX();
  15.         }
  16.  
  17.         @Override
  18.         public void onUpdate(float pSecondsElapsed) {
  19.           super.onUpdate(pSecondsElapsed);
  20.  
  21.           if (cameraPreviousX != this.camera.getMinX()) {
  22.             cameraOffsetX = cameraPreviousX - this.camera.getMinX();
  23.             cameraPreviousX = this.camera.getMinX();
  24.            
  25.             this.mParallaxValue += cameraOffsetX;
  26.           }
  27.          
  28.         }
  29.  
  30. }
  31.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
stormtroopa
 
Posts: 28
Joined: Sun Jan 30, 2011 8:27 pm

Re: Scrollable Parallax Background

Postby virtual » Wed Jan 18, 2012 12:36 pm

Thank you, guys, for answers!

ill2005
I despaired and gave up the case and acted simply: just add the very first background's sprite, filled with light blue color with speed = 0;

code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. float ZERO_SPEED = 0;
  2. backgroundParallax.addSprite(0, 0, 800, 480, ZERO_SPEED, "JUST_BLUE.png", this); //<-------This
  3. backgroundParallax.addSprite(0, 0, 800, 480, -2, "sky.png", this); //My old background with bug
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


And now all ok.

You can see my app on google market: https://market.android.com/details?id=com.huxtus.puzzle.
Also several links (include direct link to apk) here: https://sites.google.com/site/huxtussoft/home-1/games/honey-bee-puzzle/honey-bee-puzzle-download

stormtroopa
:) You all right!
Just my code is based on topic starter's code. I changed base class to AutoParallaxBackground, added addSprite method and...that's all folks :)
virtual
 
Posts: 38
Joined: Tue Jan 03, 2012 12:05 pm
Location: Russia

Re: Scrollable Parallax Background

Postby Sasukexkun » Thu Feb 16, 2012 7:37 pm

Hey guys, Is it difficult or tough to change touch screen method into digital on screen control for the scrollable parallax background. If possible, can anyone give me some idea or short sniplet of codes to change the method.

I am new on AndEngine as i am trying to learn all the basics element. Thank you in advance.
Sasukexkun
 
Posts: 5
Joined: Sun Feb 12, 2012 6:13 pm

Re: Scrollable Parallax Background

Postby Spamavert » Tue Feb 21, 2012 6:45 pm

I was experiencing the flickering line problem as well when using BILINEAR_PREMULTIPLYALPHA. For any newcomers, the problem is caused by the fact that bilinear interpolation uses pixels outside of the texture to increase the picture's resolution. As a result, the sides of the texture are being poisoned by the color of pixels outside of the texture. In order to keep using BILINEAR options, I made a nasty little kludge that vastly improves the situation. Here's the code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundBitmapTexture, this, "background.png", 0, 0);
  2. BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundBitmapTexture, this, "background.png", 2, 0);
  3. this.backgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundBitmapTexture, this, "background.png", 1, 0);
  4.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

This copies the line of pixels on the left and right side of the picture. It is better to make these changes in the original texture, but right now I just wanted to have a good looking scene.
Spamavert
 
Posts: 7
Joined: Fri Jan 06, 2012 12:52 pm

Re: Scrollable Parallax Background

Postby Spamavert » Tue Feb 21, 2012 6:59 pm

Is there anyone who has an idea of how the ParallaxBackground actually works? I added a code that allows me to zoom in and out but now I have two problems that are probably closely related to each other:

1. The rate at which the background moves with respect to the scene changes as I zoom.

2. The background texture is copied to both sides of the visible scene. Let's call them Left, Middle and Right background. When I zoom out, the ScrollableParallaxBackground assumes I still only see the part of the scene I saw when I loaded it and so when Middle background sticks out of the originally visible scene, the Left background is unloaded and replaced with plain black. If problem 1. is fixed, this would probably not be a problem for background that is behind the rest of the scene, but if I had a foreground picture, the problem would persist.

I assume I have to somehow dynamically change the Camera, but I have no idea how.

For reference, here's the code that allows me to zoom:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     @Override
  2.     public void onDraw(final GL10 pGL, final Camera pCamera) {
  3.        pCamera.onApplySceneMatrix(pGL);
  4.        GLHelper.setModelViewIdentityMatrix(pGL);
  5.        super.onDraw(pGL, pCamera);
  6.     }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Spamavert
 
Posts: 7
Joined: Fri Jan 06, 2012 12:52 pm

Re: Scrollable Parallax Background

Postby jaym » Sat Mar 03, 2012 6:02 am

Working on new class
Last edited by jaym on Tue Mar 06, 2012 3:30 am, edited 1 time in total.
AndEngine for Android Game Development Cookbook - Based on AndEngine's latest, greatest, GLES2.0 AnchorCenter branch!
jaym
 
Posts: 690
Joined: Wed May 04, 2011 10:08 pm

Re: Scrollable Parallax Background

Postby OzLark » Sat Mar 03, 2012 2:54 pm

jaym wrote:This class is based on GLES20


Excellent! - So now I have animated scrollable and zoomable parallax background and I've gone from 24fps when using the original scrollable parallax background to 36 - 37fps - a gain of 12-13fps!!

Top work, thanks for sharing.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: [Update] ParallaxLayer

Postby jaym » Tue Mar 06, 2012 3:34 am

I've updated the first post with the new Parallax Layer class. If you use Parallax Entities in any of your games it is a must see. Make sure to read all of the points before deciding that you don't want to use, it does include some more performance increases.
AndEngine for Android Game Development Cookbook - Based on AndEngine's latest, greatest, GLES2.0 AnchorCenter branch!
jaym
 
Posts: 690
Joined: Wed May 04, 2011 10:08 pm

Re: [Update] ParallaxLayer

Postby OzLark » Tue Mar 06, 2012 10:16 am

I've tried out this latest version, but reverted back to the one you had up a few days ago.

I have some fog like scrolling entities, that when using the latest version I get nasty edges (missing line?, extra line?) between entities.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

PreviousNext

Return to Features

Who is online

Users browsing this forum: No registered users and 2 guests