Hello everyone!
I am almost pretty sure this is quite a noob question, but I’ve searched around all forum and haven’t really found an answer to my problem.
I am developing a game and now I am porting it to android.
That stuff about AndroidHarness and etc does really makes things simpler to port.
But I noticed that my screen is streched.
First I would make some considerations:
- My game is portrait mode only.
- During pc execution, graphics are ok.
- I have a LG G4 (screen resolution is 1440x2332 or something like that)
The code:
MainActivity.java (removed only the rest which is default from ide generation)
public MainActivity(){
/* ... */
screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
/* ... */
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adjustResolution();
}
protected void adjustResolution() {
if (view != null) {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
view.getHolder().setFixedSize(480, 640);
}
});
}
}
Game.java
public class PuzzleFighterApp extends SimpleApplication {
/* variable declared */
/* ... */
public static AppSettings getSettings()
{
if(settings==null)
{
settings = new AppSettings(true);
settings.setFrameRate(60);
settings.setFrequency(60);
settings.setResolution(480, 640);
}
return settings;
}
public static void main(String[] args) {
GameApp app = new GameApp();
app.setShowSettings(false);
settings = getSettings();
app.setSettings(settings);
app.start();
}
@Override
public void simpleInitApp() {
settings = getSettings();
getFlyByCamera().setEnabled(false);
inputManager.setCursorVisible(true);
viewPort.setBackgroundColor(new ColorRGBA(0.1f, 0.5f, 0.4f, 1f));
this.stateManager.attach(new GameAppState());
}
@Override
public void simpleUpdate(float tpf) { }
@Override
public void simpleRender(RenderManager rm) { }
}
I tried to remove setResolution at my getSettings just to check. As my game uses screen size to organize stuff in screen it uses the wrong resolution and distribute the items wrongly and yet all images are streched.
If I keep setResolution at my getSettings and remove view.getHolder().setFixedSize(480, 640) from MainActivity I noticed that setResolution set only configurations related to jme stuff (inputManager etc) but does not set the correct resolution. As my phone has this kinda high resolution I’ve got very little images and they are not distorted.
So I believe the strech occurs because of view.getHolder().setFixedSize(480, 640) but without it I can’t make it get the right resolution I want.
Also I have a Motorola Moto E and Motorola Moto E2 for testing. The same problem occurs
Here is a screenshot on my G4:
http://167.160.170.122/alpaca/screenshot_distorted.png
Notice that they are not exactly squares. They are higher than larger. (I would guess they have the proportion of my screen resolution but I didn’t check )
(obs:they are not quads they are pictures)
Can anyone give me a tip on this ?