Vertical Parallax Background

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

Vertical Parallax Background

Postby Method » Fri Dec 17, 2010 11:50 pm

Hi there, I'm new to these forums but recently I have been building a small game which I hope to release on the market within the next few days.

Using this engine, I have come to these forums a lot and appreciate all they offer, so I thought I would add a few of the smaller things I have made to hopefully add a little bit back towards the project.

Here I have a class that simply extends the ParallaxEntity class, and using these will make your background go upwards.

*NOTE* For my game, my backgrounds use BILINEAR filtering, which causes the edges to receive off-texture bleed, this causes seams in between each background texture as it scrolls, I added a -1 offset to the reported height of the texture, to allow a one pixel drawing overlap, which hides the seam. If your game does not use BLINEAR filtering, or you have other fixes in play for this, you may want to remove the -1 offset.

Use in the same fashion you would use the original (refer to AndEngine Examples)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class VerticalParallaxEntity extends ParallaxEntity {
  2.        
  3.         protected float mParallaxFactor;
  4.         protected Shape mShape;
  5.  
  6.         public void onDraw(GL10 pGL, float pParallaxValue, Camera pCamera) {
  7.                 pGL.glPushMatrix();
  8.                 {
  9.                         final float cameraHeight = pCamera.getHeight();
  10.                         final float shapeHeightScaled = this.mShape.getHeightScaled()-1;
  11.                         //minus 1 creates overlap to remove texture seams (caused by Bilinear filtering)
  12.                         float baseOffset = (pParallaxValue * this.mParallaxFactor) % shapeHeightScaled;
  13.  
  14.                         while(baseOffset > 0) {
  15.                                 baseOffset -= shapeHeightScaled;
  16.                         }
  17.                         pGL.glTranslatef(0, baseOffset, 0);
  18.  
  19.                         float currentMaxY = baseOffset;
  20.  
  21.                         do {
  22.                                 this.mShape.onDraw(pGL, pCamera);
  23.                                 pGL.glTranslatef(0, shapeHeightScaled, 0);
  24.                                 currentMaxY += shapeHeightScaled;
  25.                         } while(currentMaxY < cameraHeight);
  26.                 }
  27.                 pGL.glPopMatrix();
  28.         }
  29.  
  30.         public VerticalParallaxEntity(float pParallaxFactor, Shape pShape) {
  31.                 super(pParallaxFactor, pShape);
  32.                 this.mParallaxFactor = pParallaxFactor;
  33.                 this.mShape = pShape;
  34.         }
  35.  
  36. }
Parsed in 0.014 seconds, using GeSHi 1.0.8.4
Method
 
Posts: 2
Joined: Fri Dec 17, 2010 11:43 pm

Return to Features

Who is online

Users browsing this forum: No registered users and 10 guests