Orientation Change Question

  ... the Live-Wallpaper Extension for AndEngine.

Orientation Change Question

Postby itspers » Wed Dec 07, 2011 1:01 am

I made nice code that takes screen size in onLoadEngine() to create camera and engine, than create textures based on this size in onLoadResources() and give right positions for elements in onLoadScene(). This works perfect for any screen if it started in portration or lanscape orientation. But how to refresh it on orientation change?

I trying to run this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 this.mEngine = this.onLoadEngine();
  2.                 this.onLoadResources();
  3.                 final Scene scene = this.onLoadScene();
  4.                 this.mEngine.onLoadComplete(scene);
  5.                 this.onLoadComplete();
  6.                 this.mEngine.start();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

when orientation change, seems that it creates new camera and scene with right size, but screen becomes scaled by X. Why this happens if i create new camera?
itspers
 
Posts: 1
Joined: Tue Dec 06, 2011 9:14 pm

Re: Orientation Change Question

Postby liquidair » Tue Dec 13, 2011 9:13 am

anytime the screen is rotated the system will call the method in

GLWallpaperService.java -> onSurfaceChanged();

What I did was I wrote in interface that calls a listener method if not null that trickles the new surface area dims back up to the main LivewallpaperService.java class. Then, I modifed the engine by adding the following to Camera.java

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void setCameraWidthHeight(final float pWidth, final float pHeight)
  2. {
  3.   this.mMaxX = pWidth;
  4.   this.mMaxY = pHeight;
  5. }
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I called this above code within the LiveWallpaperService.java and it fixes the rotation issue or the screen skewing issue
while(dream == true) { Z++; }
http://www.joshideas.com
liquidair
 
Posts: 43
Joined: Fri Dec 31, 2010 4:47 am

Re: Orientation Change Question

Postby SPi » Sat Jan 07, 2012 11:29 am

Hi!
I am having the same problem as the OP.
Since the thread has seen a few days, I wondered if there is a built-in solution yet, which I did not find?
Or do you still need to alter the engine?
onSurfaceChanged() is available now for liveWallpapers, but:
camera.setSurfaceSize does not seem to have any effect?
same as engine.setSurfaceSize
scene.scale does not scale the parallax background

thanks
SPi
 
Posts: 2
Joined: Sat Jan 07, 2012 11:23 am

Re: Orientation Change Question

Postby navossoc » Fri Jan 27, 2012 12:07 am

SPi wrote:Hi!
I am having the same problem as the OP.
Since the thread has seen a few days, I wondered if there is a built-in solution yet, which I did not find?
Or do you still need to alter the engine?
onSurfaceChanged() is available now for liveWallpapers, but:
camera.setSurfaceSize does not seem to have any effect?
same as engine.setSurfaceSize
scene.scale does not scale the parallax background

thanks


Good question, still looking for a answer to this.
No one solved it? or no one share it?

PS: After many hours of testing, I found a solution (the best I could get).

@Override
public void onSurfaceChanged(int pWidth, int pHeight) {

Log.d("LWP", "onSurfaceChanged(" + pWidth + "," + pHeight + ")");

// ...

super.onSurfaceChanged(pWidth, pHeight);
this.mEngine.getCamera().set(0, 0, pWidth, pHeight); // trick here :D

}


Don't have any ideia if the set() should come after or before super call.
Seems to work fine in both way.

[]'s
navossoc
 
Posts: 3
Joined: Thu Aug 11, 2011 2:22 am


Return to Live-Wallpaper

Who is online

Users browsing this forum: No registered users and 2 guests