[SOLVED]How wallpaper scroll along with homescreen?

  ... the Live-Wallpaper Extension for AndEngine.

[SOLVED]How wallpaper scroll along with homescreen?

Postby Kangee » Wed Aug 25, 2010 10:57 am

Hi @ll,

after my first quick successes (Sprites moving on the screen and interact with each other) with AndEngine i try to implement my frist live wallpaper - a simple aquarium (Fishes moving from one site to the other site).
And yeah it was very simple to implement that - thanks to AndEngine :-)
But when i move from one homescreen to the next homescreen the wallpaper scene was still the same. I thought to the nexus wallpaper where i can follow a ray through the screens.
But how can i implement that. My frist idea was the change the camera position on a touchevent based on the "Scrolling with Touch Events"-Tutorial but i dosen't works for me :-(
Has anyone an idea how i can implement that?

Greetings,
Kangee

P.S.: I am from germany - i hope my english is good enough to understand my question :-)
Kangee
 
Posts: 9
Joined: Tue Aug 17, 2010 11:22 pm
Location: near Bremen, Germany

Re: How wallpaper scroll along with homescreen?

Postby Kangee » Sun Aug 29, 2010 4:50 pm

No answers :-( do you don't unterstand my question?

Btw: This weekend i had time to work on my problem and i read this: "to scroll along when the user swipes from one home screen to another, you can use onOffsetsChanged()" Source: http://developer.android.com/resources/ ... apers.html

So i looked into the "Live-Wallpaper Extension Source" and saw that there is no implementaion of the onOffsetsChanged() method into BaseWallpaperGLEngine class.
I tried to build my own version of the Live-Wallpaper Extension which push the onOffsetsChanged Event to the BaseLiveWallpaperService class but if i used this version my "live wallpaper"-app throws a exception during the start :-(
Kangee
 
Posts: 9
Joined: Tue Aug 17, 2010 11:22 pm
Location: near Bremen, Germany

Re: How wallpaper scroll along with homescreen?

Postby Kangee » Mon Aug 30, 2010 8:50 pm

Solved the problem by myself
Kangee
 
Posts: 9
Joined: Tue Aug 17, 2010 11:22 pm
Location: near Bremen, Germany

Re: How wallpaper scroll along with homescreen?

Postby Mimminito » Mon Aug 30, 2010 10:16 pm

Sorry I didnt see this post till today. But I dont think I would have been much help anyways :)

Glad its sorted now. I dont suppose you want to post your code for others to look at? Might help people out in the future.
---------------------------------------
Adam Goodchild
Your AndEngine Forum Moderator!
My Tutorials List
http://www.adam-goodchild.co.uk
---------------------------------------
Mimminito
 
Posts: 360
Joined: Wed Jul 21, 2010 3:08 pm
Location: Chelsmford, UK

Re: How wallpaper scroll along with homescreen?

Postby Kangee » Mon Aug 30, 2010 10:39 pm

Mimminito wrote:I dont suppose you want to post your code for others to look at? Might help people out in the future.


I will help ;-) because i like andengine and i hope that the community grows up to make it better and better.

So the problem was - i posted it out in post#2 - the BaseWallpaperGLEngine class in the BaseLiveWallpaperService. To scroll along with the homescreen we need to implement the onOffsetsChanged() method.
So i implement my own Version of BaseWallpaperGLEngine (copy the old stuff and extend it with the onOffsetsChanged() method):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         protected class MyBaseWallpaperGLEngine extends GLEngine {
  3.                 // ===========================================================
  4.                 // Fields
  5.                 // ===========================================================
  6.  
  7.                 private Renderer mRenderer;
  8.                
  9.                 private IOffsetsChanged mOffsetsChangedListener = null;
  10.  
  11.                 // ===========================================================
  12.                 // Constructors
  13.                 // ===========================================================
  14.  
  15.                 public MyBaseWallpaperGLEngine(IOffsetsChanged pOffsetsChangedListener) {
  16.                         this.setEGLConfigChooser(false);
  17.                         this.mRenderer = new RenderSurfaceView.Renderer(LiveWallpaperTemplate.this.mEngine);
  18.                         this.setRenderer(this.mRenderer);
  19.                         this.setRenderMode(RENDERMODE_CONTINUOUSLY);
  20.                         this.mOffsetsChangedListener = pOffsetsChangedListener;
  21.                 }
  22.  
  23.                 // ===========================================================
  24.                 // Methods for/from SuperClass/Interfaces
  25.                 // ===========================================================
  26.  
  27.                 @Override
  28.                 public Bundle onCommand(final String pAction, final int pX, final int pY, final int pZ, final Bundle pExtras, final boolean pResultRequested) {
  29.                         if(pAction.equals(WallpaperManager.COMMAND_TAP)) {
  30.                                 LiveWallpaperTemplate.this.onTap(pX, pY);
  31.                         } else if (pAction.equals(WallpaperManager.COMMAND_DROP)) {
  32.                                 LiveWallpaperTemplate.this.onDrop(pX, pY);
  33.                         }
  34.  
  35.                         return super.onCommand(pAction, pX, pY, pZ, pExtras, pResultRequested);
  36.                 }
  37.  
  38.                 @Override
  39.                 public void onResume() {
  40.                         super.onResume();
  41.                         LiveWallpaperTemplate.this.getEngine().onResume();
  42.                         LiveWallpaperTemplate.this.onResume();
  43.                 }
  44.  
  45.                 @Override
  46.                 public void onPause() {
  47.                         super.onPause();
  48.                         LiveWallpaperTemplate.this.getEngine().onPause();
  49.                         LiveWallpaperTemplate.this.onPause();
  50.                 }
  51.  
  52.                 @Override
  53.                 public void onDestroy() {
  54.                         super.onDestroy();
  55.                         if (this.mRenderer != null) {
  56.                                 // mRenderer.release();
  57.                         }
  58.                         this.mRenderer = null;
  59.                 }
  60.                
  61.                 @Override
  62.                 public void onOffsetsChanged(float xOffset, float yOffset,
  63.                                 float xOffsetStep, float yOffsetStep, int xPixelOffset,
  64.                                 int yPixelOffset) {
  65.                         // TODO Auto-generated method stub
  66.                         super.onOffsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep,
  67.                                         xPixelOffset, yPixelOffset);
  68.                        
  69.                         if(this.mOffsetsChangedListener != null)
  70.                                 this.mOffsetsChangedListener.offsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep, xPixelOffset, yPixelOffset);
  71.                                        
  72.                 }
  73.                
  74.         }
  75.  
  76.  
Parsed in 0.016 seconds, using GeSHi 1.0.8.4



I also create a Interface IOffsetsChanged (you see it in the constructor) which LiveWallpaperTemplate class (if you used Mimminito Live-Wallpaper-Template) implement and i override in LiveWallpaperTemplate the onCreateEngine method.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public Engine onCreateEngine() {
  3.                 // TODO Auto-generated method stub
  4.                 return new MyBaseWallpaperGLEngine(this);
  5.         }
  6.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public interface IOffsetsChanged{
  3.        
  4.         public void offsetsChanged(float xOffset, float yOffset,
  5.                         float xOffsetStep, float yOffsetStep, int xPixelOffset,
  6.                         int yPixelOffset);
  7.        
  8. }
  9.  
  10.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4



Now we get a callback if the user scroll. But we have to scroll our camera with and the solution for this problem is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public void offsetsChanged(float xOffset, float yOffset, float xOffsetStep,
  3.                         float yOffsetStep, int xPixelOffset, int yPixelOffset) {
  4.                 // TODO Auto-generated method stub
  5.                
  6.                 if(mCamera != null){
  7.                        
  8.                               //Emulator has 3 screens
  9.                         mCamera.setCenter( ((960 * xOffset ) - 240) , mCamera.getCenterY() );
  10.                         /*formel                mCamera.setCenter(( (Camera-WIDTH * (screensCount-1)) * xOffset ) - (Camera-WIDTH / 2) ,mCamera.getCenterY() ); */
  11.                 }
  12.  
  13.         }
  14.  
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
Last edited by Kangee on Mon Aug 30, 2010 10:42 pm, edited 1 time in total.
Kangee
 
Posts: 9
Joined: Tue Aug 17, 2010 11:22 pm
Location: near Bremen, Germany

Re: [SOLVED]How wallpaper scroll along with homescreen?

Postby Mimminito » Mon Aug 30, 2010 10:41 pm

Brilliant, thanks. I am sure this will help some people out (even if you get no replies :))
---------------------------------------
Adam Goodchild
Your AndEngine Forum Moderator!
My Tutorials List
http://www.adam-goodchild.co.uk
---------------------------------------
Mimminito
 
Posts: 360
Joined: Wed Jul 21, 2010 3:08 pm
Location: Chelsmford, UK

Re: [SOLVED]How wallpaper scroll along with homescreen?

Postby Kangee » Mon Aug 30, 2010 10:48 pm

Maybe Nicolas could fix the problem directly in the LivePaper-Extension source-code - i think that will be better.
Kangee
 
Posts: 9
Joined: Tue Aug 17, 2010 11:22 pm
Location: near Bremen, Germany

Re: [SOLVED]How wallpaper scroll along with homescreen?

Postby PowerApps » Sun Oct 17, 2010 12:59 am

I tried implementing your code into the base live wallpaper template but couldn't get it as it was riddled with errors. Do you have any suggestions?
EDIT:
I fixed all the errors they were just me being an idiot but, it's still not scrolling.
PowerApps
 
Posts: 23
Joined: Fri Aug 13, 2010 11:03 pm

Re: [SOLVED]How wallpaper scroll along with homescreen?

Postby Kangee » Mon Oct 25, 2010 9:25 am

Hi PowerApps,

i was not the last days at home. This evening i will check my code - maybe i make a mistake in the quoted code.
Kangee
 
Posts: 9
Joined: Tue Aug 17, 2010 11:22 pm
Location: near Bremen, Germany

Re: [SOLVED]How wallpaper scroll along with homescreen?

Postby PowerApps » Tue Oct 26, 2010 4:04 am

Ok, thanks I was just curious as I recently finished my first app and I think it would make it a little better.
PowerApps
 
Posts: 23
Joined: Fri Aug 13, 2010 11:03 pm

Next

Return to Live-Wallpaper

Who is online

Users browsing this forum: No registered users and 3 guests