[Update] ParallaxLayer

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

Re: [Update] ParallaxLayer

Postby MuadDib » Wed Dec 11, 2013 11:18 am

Hello everybody,

jaym - thx this is a great class! Is there any news or update, for working in both X and Y axis?

Thx again
MuadDib
 
Posts: 6
Joined: Mon Nov 25, 2013 4:39 pm

Re: [Update] ParallaxLayer

Postby Blackchart » Sun Dec 15, 2013 1:53 am

Hello guys,
It's my first day with ParallaxLayer and... I have a little problem.
When I try add attachParallaxEntity eclipse returns me following error:
The method attachParallaxEntity(ParallaxLayer.ParallaxEntity) in the type ParallaxLayer is not applicable for the arguments (ParallaxBackground.ParallaxEntity)
What I'm doing wrong? I'm using ParallexLayer class from first page of this topic.
It's my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Game extends SimpleBaseGameActivity {
  2.         private static int CAMERA_WIDTH = 800;
  3.         private static int CAMERA_HEIGHT = 460;
  4.        
  5.         private SmoothCamera camera;
  6.         private  ITextureRegion mrace_theme, mrace_marks;
  7.         ParallaxLayer parallaxLayer = new ParallaxLayer(camera, true, 4000);
  8.  
  9.        
  10.         @Override
  11.         public EngineOptions onCreateEngineOptions() {
  12.                 final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  13.                 return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
  14.                     new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
  15.         }
  16.  
  17.         @Override
  18.         protected void onCreateResources() {
  19.                 try {
  20.                     // 1 - Set up bitmap textures
  21.                     ITexture race_theme = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
  22.                         @Override
  23.                         public InputStream open() throws IOException {
  24.                             return getAssets().open("gfx/race_road.png");
  25.                         }
  26.                     });
  27.                     ITexture race_marks = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
  28.                         @Override
  29.                         public InputStream open() throws IOException {
  30.                             return getAssets().open("gfx/race_marks.png");
  31.                         }
  32.                     });
  33.                    
  34.                     // 2 - Load bitmap textures into VRAM
  35.                     race_theme.load();
  36.                     race_marks.load();
  37.                     this.mrace_theme = TextureRegionFactory.extractFromTexture(race_theme);
  38.                     this.mrace_marks = TextureRegionFactory.extractFromTexture(race_marks);
  39.  
  40.                 } catch (IOException e) {
  41.                     Debug.e(e);
  42.                 }      
  43.         }
  44.  
  45.         @Override
  46.         protected Scene onCreateScene() {
  47.                 Scene scene = new Scene();
  48.                 ParallaxLayer parallaxLayer = new ParallaxLayer(camera, true, 4000);
  49.                
  50.                 Sprite Srace_theme = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, mrace_theme, this.getVertexBufferObjectManager());
  51.                 Sprite Srace_marks = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, mrace_marks, this.getVertexBufferObjectManager());          
  52.                 parallaxLayer.setParallaxChangePerSecond(1);
  53.                 parallaxLayer.setParallaxScrollFactor(0);
  54.                
  55.                 parallaxLayer.attachParallaxEntity(new ParallaxEntity(0, Srace_marks));
  56.                 //The method attachParallaxEntity(ParallaxLayer.ParallaxEntity) in the type ParallaxLayer is not applicable for the arguments (ParallaxBackground.ParallaxEntity)
  57.  
  58.         scene.attachChild(parallaxLayer);
  59.                 return scene;
  60.         }
  61. }
Parsed in 0.014 seconds, using GeSHi 1.0.8.4
Blackchart
 
Posts: 6
Joined: Sun Dec 15, 2013 1:46 am

Re: [Update] ParallaxLayer

Postby nazgee » Sun Dec 15, 2013 2:09 am

Wrong import due to name clash.
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: [Update] ParallaxLayer

Postby Blackchart » Sun Dec 15, 2013 2:13 am

Sorry but i dont see my mistake... could you fix it for me? Please.
Blackchart
 
Posts: 6
Joined: Sun Dec 15, 2013 1:46 am

Re: [Update] ParallaxLayer

Postby nazgee » Sun Dec 15, 2013 12:15 pm

Paste your imports you have in this file.
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: [Update] ParallaxLayer

Postby Blackchart » Sun Dec 15, 2013 12:19 pm

All my imports:
And my whole code: http://pastebin.com/gQfrF3mh

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import java.io.IOException;
  2. import java.io.InputStream;
  3.  
  4. import org.andengine.engine.camera.Camera;
  5. import org.andengine.engine.camera.SmoothCamera;
  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.scene.background.AutoParallaxBackground;
  11. import org.andengine.entity.scene.background.ParallaxBackground;
  12. import org.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
  13. import org.andengine.entity.sprite.Sprite;
  14. import org.andengine.entity.util.FPSLogger;
  15. import org.andengine.opengl.texture.ITexture;
  16. import org.andengine.opengl.texture.bitmap.BitmapTexture;
  17. import org.andengine.opengl.texture.region.ITextureRegion;
  18. import org.andengine.opengl.texture.region.TextureRegion;
  19. import org.andengine.opengl.texture.region.TextureRegionFactory;
  20. import org.andengine.ui.activity.SimpleBaseGameActivity;
  21. import org.andengine.util.adt.io.in.IInputStreamOpener;
  22. import org.andengine.util.debug.Debug;
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
Blackchart
 
Posts: 6
Joined: Sun Dec 15, 2013 1:46 am

Re: [Update] ParallaxLayer

Postby ralle2312 » Sun Dec 22, 2013 10:04 pm

Hi, i want this use in the LiveWallpaper , i have but a big Problem. Please help me.

Greats Ralf

My Code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.mobi.christmaslivewallpaper;
  2.  
  3. import org.andengine.engine.camera.Camera;
  4. import org.andengine.engine.options.EngineOptions;
  5. import org.andengine.engine.options.ScreenOrientation;
  6. import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  7. import org.andengine.entity.scene.IOnAreaTouchListener;
  8. import org.andengine.entity.scene.IOnSceneTouchListener;
  9. import org.andengine.entity.scene.ITouchArea;
  10. import org.andengine.entity.scene.Scene;
  11. import org.andengine.entity.sprite.Sprite;
  12. import org.andengine.extension.ui.livewallpaper.BaseLiveWallpaperService;
  13. import org.andengine.input.touch.TouchEvent;
  14. import org.andengine.input.touch.detector.SurfaceScrollDetector;
  15. import org.andengine.input.touch.detector.ScrollDetector;
  16. import org.andengine.input.touch.detector.ScrollDetector.IScrollDetectorListener;
  17. import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
  18. import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
  19. import org.andengine.opengl.texture.region.ITextureRegion;
  20. import org.andengine.opengl.vbo.VertexBufferObjectManager;
  21. import com.mobi.christmaslivewallpaper.ParallaxLayer;
  22. import com.mobi.christmaslivewallpaper.ParallaxLayer.ParallaxEntity;
  23. import android.content.res.Resources;
  24. import android.util.Log;
  25. import android.view.MotionEvent;
  26.  
  27.  
  28.  
  29. public class LiveWallpaperService extends BaseLiveWallpaperService implements IOnSceneTouchListener, IScrollDetectorListener{
  30.     private static int CAMERA_WIDTH;
  31.    private static int CAMERA_HEIGHT;
  32.     private Camera mCamera ;
  33.     private Scene mScene;
  34.    
  35.     //private int CAMERA_WIDTH = 1024;
  36.         //private int CAMERA_HEIGHT = 1024;
  37.         //private Camera manokamera ;
  38.         //private Scene manoscena;
  39.    
  40.     private BitmapTextureAtlas Back1_Atlas;
  41.     private ITextureRegion Back1_Region;
  42.    
  43.     private BitmapTextureAtlas Back2_Atlas;
  44.     private ITextureRegion Back2_Region;
  45.            
  46.     private ScrollDetector myScrollDetector;
  47.    
  48.     @Override
  49.     public EngineOptions onCreateEngineOptions() {
  50.         Resources res = getResources();
  51.         CAMERA_HEIGHT = res.getDisplayMetrics().heightPixels;
  52.         CAMERA_WIDTH = res.getDisplayMetrics().widthPixels;
  53.         mCamera = new Camera(0,0,CAMERA_WIDTH, CAMERA_HEIGHT);
  54.         return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
  55.        
  56.     }
  57.  
  58.    
  59.     @Override
  60.     public void onCreateResources(
  61.                     OnCreateResourcesCallback pOnCreateResourcesCallback)
  62.                     throws Exception {
  63.        
  64.             Back1_Atlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024);
  65.             Back1_Region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(Back1_Atlas,this.getAssets(), "gfx/back1.png", 0, 0);
  66.             Back1_Atlas.load();
  67.            
  68.             Back2_Atlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024);
  69.             Back2_Region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(Back2_Atlas,this.getAssets(), "gfx/back2.png", 0, 0);
  70.             Back2_Atlas.load();
  71.            
  72.             pOnCreateResourcesCallback.onCreateResourcesFinished();
  73.             }
  74.    
  75.     @Override
  76.     public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
  77.                     throws Exception {
  78.             mScene = new Scene();
  79.             final ParallaxLayer parallaxLayer = new ParallaxLayer(mCamera, true, 4000);
  80.             final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
  81.            
  82.             parallaxLayer.setParallaxChangePerSecond(8);
  83.             parallaxLayer.setParallaxScrollFactor(1);
  84.            
  85.             Sprite Back1Sprite = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, this.Back1_Region,vertexBufferObjectManager);
  86.             Sprite Back2Sprite = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, this.Back2_Region,vertexBufferObjectManager);
  87.  
  88.             parallaxLayer.attachParallaxEntity(new ParallaxEntity(1, Back1Sprite, true));
  89.             parallaxLayer.attachParallaxEntity(new ParallaxEntity(-2, Back2Sprite, false, 1));
  90.            
  91.             mScene.attachChild(parallaxLayer);
  92.             mScene.setOnSceneTouchListener(this);
  93.             //this.myScrollDetector = new SurfaceScrollDetector(this);
  94.             //this.myScrollDetector.setEnabled(true);
  95.    
  96.             //Engine.setTouchEventsEnabled(true);
  97.            // mScene.setTouchAreaBindingOnActionDownEnabled(true);
  98.    
  99.             pOnCreateSceneCallback.onCreateSceneFinished(mScene);
  100.     }
  101.  
  102.     @Override
  103.     public void onPopulateScene(Scene pScene,
  104.                     OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
  105.             pOnPopulateSceneCallback.onPopulateSceneFinished();
  106.     }
  107.  
  108.  
  109.  
  110.  // Scrolling
  111.     private float mTouchX = 0, mTouchOffsetX = 0;
  112.  
  113.  
  114.     public boolean onSceneTouchEvent(Scene pScene, TouchEvent pTouchEvent) {
  115.  
  116.             if (pTouchEvent.getAction() == MotionEvent.ACTION_DOWN) {
  117.                     mTouchX = pTouchEvent.getMotionEvent().getX();
  118.             } else if (pTouchEvent.getAction() == MotionEvent.ACTION_MOVE) {
  119.                     float newX = pTouchEvent.getMotionEvent().getX();
  120.  
  121.                     mTouchOffsetX = (newX - mTouchX);
  122.  
  123.        //             backgroundParallax.updateScrollEvents();
  124.  
  125.                     float newScrollX = this.mCamera.getCenterX() - mTouchOffsetX;
  126.  
  127.                     this.mCamera.setCenter(newScrollX, this.mCamera.getCenterY());
  128.                     mTouchX = newX;
  129.             }
  130.             return true;
  131.     }
  132.  
  133.  
  134.  
  135.  
  136. @Override
  137. public void onScroll(ScrollDetector pScollDetector, int pPointerID,
  138.                 float pDistanceX, float pDistanceY) {
  139.             this.mCamera.setCenter(mCamera.getCenterX() - pDistanceX, mCamera.getCenterY());
  140. }
  141.  
  142.  
  143.  
  144. @Override
  145. public void onScrollFinished(ScrollDetector pScollDetector, int pPointerID,
  146.                 float pDistanceX, float pDistanceY) {
  147.             this.mCamera.setCenter(mCamera.getCenterX() - pDistanceX, mCamera.getCenterY());
  148. }
  149.  
  150.  
  151.  
  152. @Override
  153. public void onScrollStarted(ScrollDetector pScollDetector, int pPointerID,
  154.                 float pDistanceX, float pDistanceY) {
  155.         // TODO Auto-generated method stub
  156. }
  157.  
  158. }
Parsed in 0.019 seconds, using GeSHi 1.0.8.4
ralle2312
 
Posts: 14
Joined: Tue Dec 03, 2013 8:21 pm
Location: Germany

Re: [Update] ParallaxLayer

Postby ralle2312 » Mon Dec 23, 2013 1:31 pm

Hi,

I want to create a multi Background.Unfortunately, it does not by touch, nothing moves. Perhaps someone has a tip for me. Sorry my Englisch is not so good.

Greats Ralf
ralle2312
 
Posts: 14
Joined: Tue Dec 03, 2013 8:21 pm
Location: Germany

Re: [Update] ParallaxLayer

Postby princetontiger » Thu Feb 13, 2014 11:44 pm

nevermind.
Last edited by princetontiger on Fri Feb 14, 2014 7:10 am, edited 1 time in total.
Image
princetontiger
 
Posts: 64
Joined: Tue Jun 14, 2011 1:37 pm

Re: [Update] ParallaxLayer

Postby princetontiger » Fri Feb 14, 2014 7:07 am

Blackchart:

use

new ParallaxLayer.ParallaxEntity instead of ParallaxEntity
Image
princetontiger
 
Posts: 64
Joined: Tue Jun 14, 2011 1:37 pm

PreviousNext

Return to Features

Who is online

Users browsing this forum: No registered users and 10 guests