JME3.0 - Images streched on android

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 :wink: )
(obs:they are not quads they are pictures)

Can anyone give me a tip on this ?

motbus,

I have ported games from jMonkey to Android.

How does the image look in the original jMonkey game when run from the IDE.

Best regards

Hello @RatThing,
Thanks for your interest on this topic.
The image looks like this:
http://167.160.170.122/alpaca/pc_screenshot.png

motbus,

does this thread help?

Full screen quad

@RatThing
Hi. It kinda helped. Thanks a lot :smile:

Actually I’ve read but I didn’t want to follow because I did not want to change other things in my code. But the problem was something like that.

I would like to share the solution (it’s awful for now, but later I will make it prettier)

If anyone is reading this thread, please check the original code I’ve posted before because I will only list the changes (and will skip any possible class variable declaration etc.

MainActivity.java

  • Changed adjustResolution method to calculate the required ratio of new screen.

    protected void adjustResolution(int width, int height) {
    if (view != null) {
    WindowManager wind = this.getWindowManager();
    Display disp = wind.getDefaultDisplay();
    displayWidth= disp.getWidth();
    displayHeight = disp.getHeight();
    ratio = ((float)displayWidth/(float)displayHeight)/(480f/640f);
    this.runOnUiThread(new Runnable() {
    @Override
    public void run() {
    view.getHolder().setFixedSize((int)(480fratio), 640);
    }
    }
    /
    … */
    }

At GameApp.java

  • Made a method called getSettings (mentioned before) to receive viewport and calculate the same ratio to use at settings.setResolution. I’m not quite sure, but I’ve read jme3 I understood that although setResolution is not capable of actually setting the resolution for an Android device for example, it will share its configurations to to inputManager and other guys who actually should be updated. I’ve checked some changes of JME3.1 (which I am not actually using) and it seems that they changed the code to do this kind of stuff automatically.

    public static AppSettings getSettings(ViewPort viewport)
    {
    if(settings==null)
    {
    settings = new AppSettings(true);
    settings.setFrameRate(60);
    settings.setFrequency(60);
    if(isAndroid)
    {
    float width = (float)viewport.getCamera().getWidth();
    float height = (float)viewport.getCamera().getHeight();
    float ratio = ((float)width/(float)height)/(480f/640f);
    settings.setResolution((int)(480f*ratio), 640);
    }
    else
    {
    settings.setResolution(480, 640);
    }
    }
    return settings;
    }

Note that as viewPort is not accessible from my static method getSettings I’ve done other basic changes I am not mentioned. But I guess anyone can figure it out.

The code isn’t beautiful but it works. Check the new picture at my LG G4.
http://167.160.170.122/alpaca/fixed_mob_screenshot.png

It worked on my MotoE2 and it seems to make some logic.
I am really sorry if this post is too noob but I haven’t found it somewhere else. So I would share these simple stuff I’ve made in case any other one need it on the future.