Converting offsetsChanged in Live Wallpaper Parallax Layer

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

Converting offsetsChanged in Live Wallpaper Parallax Layer

Postby princetontiger » Fri Feb 14, 2014 5:28 pm

How do we remove offsetschanged and place something like an ontouch function that will work with samsung?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.circularvale.wallpaperegs;
  2.  
  3. import com.circularvale.wallpaperegs.ParallaxLayer.ParallaxEntity;
  4.  
  5. import org.andengine.engine.camera.Camera;
  6. import org.andengine.engine.options.EngineOptions;
  7. import org.andengine.engine.options.ScreenOrientation;
  8. import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  9. import org.andengine.entity.scene.Scene;
  10. import org.andengine.entity.sprite.Sprite;
  11. import org.andengine.entity.sprite.AnimatedSprite;
  12. import org.andengine.opengl.texture.TextureOptions;
  13. import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
  14. import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
  15. import org.andengine.opengl.texture.region.TiledTextureRegion;
  16. import org.andengine.extension.ui.livewallpaper.BaseLiveWallpaperService;
  17. import org.andengine.opengl.texture.region.ITextureRegion;
  18. import org.andengine.opengl.vbo.VertexBufferObjectManager;
  19. import org.andengine.opengl.util.GLState;
  20.  
  21. public class WallpaperActivity extends BaseLiveWallpaperService {
  22.         private int CAMERA_WIDTH = 480;
  23.         private int CAMERA_HEIGHT = 720;
  24.         private Camera manokamera ;
  25.         private Scene manoscena;
  26.         private ITextureRegion skyRegion;
  27.         private BitmapTextureAtlas skyAtlas;
  28.         private ITextureRegion cloudRegion;
  29.         private BitmapTextureAtlas cloudAtlas;
  30.         private ITextureRegion palmRegion;
  31.         private BitmapTextureAtlas palmAtlas;
  32.         private ITextureRegion catRegion;
  33.         private BitmapTextureAtlas catAtlas;
  34.        
  35.          private BitmapTextureAtlas texBanana;
  36.          private TiledTextureRegion regBanana;
  37.          private AnimatedSprite  sprBanana;
  38.        
  39.         public EngineOptions onCreateEngineOptions() {
  40.                 // TODO Auto-generated method stub
  41.                 manokamera = new Camera(0,0,CAMERA_WIDTH, CAMERA_HEIGHT);
  42.                 return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), manokamera);
  43.  
  44.         }
  45.  
  46.         public void onCreateResources(
  47.                         OnCreateResourcesCallback pOnCreateResourcesCallback)
  48.                         throws Exception {
  49.                 skyAtlas = new BitmapTextureAtlas(this.getTextureManager(), 240, 320);
  50.                 skyRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(skyAtlas,this.getAssets(), "gfx/background.png", 0, 0);
  51.                 skyAtlas.load();
  52.                 cloudAtlas = new BitmapTextureAtlas(this.getTextureManager(), 240, 320);
  53.                 cloudRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(cloudAtlas,this.getAssets(), "gfx/sky.png", 0, 0);
  54.                 cloudAtlas.load();
  55.                 palmAtlas = new BitmapTextureAtlas(this.getTextureManager(), 240, 320);
  56.                 palmRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(palmAtlas,this.getAssets(), "gfx/palm.png", 0, 0);
  57.                 palmAtlas.load();
  58.                 catAtlas = new BitmapTextureAtlas(this.getTextureManager(), 240, 320);
  59.                 catRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(catAtlas,this.getAssets(), "gfx/cat.png", 0, 0);
  60.                 catAtlas.load();
  61.                
  62.                   texBanana = new BitmapTextureAtlas(this.getTextureManager(), 150, 150, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  63.                   regBanana = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(texBanana, this.getAssets(),
  64.                     "gfx/spr_banana.png", 0, 0, 4, 2);
  65.                   texBanana.load();
  66.                
  67.                 pOnCreateResourcesCallback.onCreateResourcesFinished();
  68.                
  69.         }
  70.  
  71.     // Offset range is: 0 .. 1
  72.     private float mainOffsetX = 0.5f;
  73.  
  74.  
  75.     private class WideSprite extends Sprite
  76.     {
  77.  
  78.             public WideSprite( float pX, float pY, float pWidth,
  79.                             float pHeight, ITextureRegion pTextureRegion,
  80.                             VertexBufferObjectManager pVertexBufferObjectManager )
  81.             {
  82.                     super( pX, pY, pWidth, pHeight, pTextureRegion, pVertexBufferObjectManager );
  83.             } // WideSprite constructor
  84.  
  85.             @Override
  86. protected void draw( GLState pGLState, Camera pCamera )
  87.             {
  88.     setPosition( CAMERA_WIDTH / 2 - getWidth() / 2 + 120 * ( mainOffsetX - 0.5f ),
  89.                     CAMERA_HEIGHT / 2 - getHeight() / 2 );
  90.    
  91.     pGLState.enableDither();
  92.    
  93.     super.draw( pGLState, pCamera );
  94. } // draw overrided
  95.            
  96.     } // WideSprite
  97.  
  98.        
  99.         public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
  100.                         throws Exception {
  101.                 manoscena = new Scene();
  102.                 final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
  103.                
  104.                 final ParallaxLayer parallaxLayer = new ParallaxLayer(manokamera, true, 500);
  105.                 parallaxLayer.setParallaxChangePerSecond(6);
  106.                 parallaxLayer.setParallaxScrollFactor(5);
  107.                
  108.                 Sprite mountainsSprite = new WideSprite(0, 0, 800, 800, this.palmRegion, vertexBufferObjectManager);
  109.                 Sprite starsSprite = new WideSprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, this.skyRegion, vertexBufferObjectManager);
  110.  
  111.                 parallaxLayer.attachParallaxEntity(new ParallaxEntity(15, starsSprite, false, 1));
  112.                 parallaxLayer.attachParallaxEntity(new ParallaxEntity(5, mountainsSprite, true));
  113.                
  114.                 this.manoscena.attachChild(parallaxLayer);
  115.                
  116.                 pOnCreateSceneCallback.onCreateSceneFinished(manoscena);
  117.  
  118.                
  119.         }
  120.  
  121.         public void onPopulateScene(Scene pScene,
  122.                         OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
  123.                 pOnPopulateSceneCallback.onPopulateSceneFinished();
  124.                
  125.         }
  126.     /** Called when the activity is first created. */
  127.        
  128.         @Override
  129.     protected void onOffsetsChanged( float pXOffset, float pYOffset,
  130.             float pXOffsetStep, float pYOffsetStep, int pXPixelOffset,
  131.             int pYPixelOffset )
  132.         {
  133.  
  134.         mainOffsetX = pXOffset;
  135.        
  136.     } // onOffsetsChanged
  137.                
  138.        
  139.  
  140. }
  141.  
Parsed in 0.020 seconds, using GeSHi 1.0.8.4


THIS CODE WORKS in non-Samsung devices.
Image
princetontiger
 
Posts: 64
Joined: Tue Jun 14, 2011 1:37 pm

Return to Features

Who is online

Users browsing this forum: No registered users and 4 guests