Controll on android

Hi,
I need little example how to set eventListener for android.
I’m always getting errors related to tonegodgui keybord.
so i think it would be useful if it is possible to get full tutorial how to set up control.

And now i’m making ping pong game. I want move a platform with finger but not with the joystick, is it possible somehow to set up it in your framework ?

For screen setup, I believe you need to:

[java]
screen.setUseMultiTouch(true);
// Optional
screen.setUseKeyboardIcons(true);
[/java]

Also, you likely want to:

[java]
inputManager.setSimulateMouse(false);
[/java]

But this isn’t required.

As for moving the platform, this shouldn’t be an issue. But, I’d need a little more info on the scenario to help. Is the game 2D? 3D? is the platform a gui control? 2D framework element? Or 3D scene spatial?

Let me know if the above solves the issue. If not, I’ll need to see portions of your code to track down the specific issue.

@SetasSan said: Hi, I need little example how to set eventListener for android. I'm always getting errors related to tonegodgui keybord. so i think it would be useful if it is possible to get full tutorial how to set up control.

And now i’m making ping pong game. I want move a platform with finger but not with the joystick, is it possible somehow to set up it in your framework ?

I’ll also update the android test project I put together later today and post a link here once I find a new home for it. This should answer any and all setup/usage questions (well… quite a few of them anyways).

It’s 2d game, so i’m using your 2d framewok for making game.

here i wrote a test and in android i’m getting error

[java]
E/com.jme3.app.AndroidHarness(10806): SEVERE Exception thrown in Thread[GLThread 3735,5,main]
E/com.jme3.app.AndroidHarness(10806): java.lang.NullPointerException
E/com.jme3.app.AndroidHarness(10806): at tonegod.gui.core.Screen.setUseKeyboardIcons(Screen.java:2245)
E/com.jme3.app.AndroidHarness(10806): at mygame.Main.simpleInitApp(Main.java:41)
E/com.jme3.app.AndroidHarness(10806): at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
E/com.jme3.app.AndroidHarness(10806): at com.jme3.app.AndroidHarness.initialize(AndroidHarness.java:455)
E/com.jme3.app.AndroidHarness(10806): at com.jme3.system.android.OGLESContext.initInThread(OGLESContext.java:229)
E/com.jme3.app.AndroidHarness(10806): at com.jme3.system.android.OGLESContext.onSurfaceCreated(OGLESContext.java:205)
E/com.jme3.app.AndroidHarness(10806): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1502)
E/com.jme3.app.AndroidHarness(10806): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
[/java]

here code

[java]

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.input.RawInputListener;
import com.jme3.input.event.JoyAxisEvent;
import com.jme3.input.event.JoyButtonEvent;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;
import com.jme3.input.event.TouchEvent;
import com.jme3.math.Vector2f;
import com.jme3.renderer.RenderManager;
import tonegod.gui.core.Screen;
import tonegod.gui.framework.core.AnimElement;
import tonegod.gui.framework.core.AnimLayer;
import tonegod.gui.framework.core.QuadData;

/**

  • test

  • @author normenhansen
    */
    public class Main extends SimpleApplication implements RawInputListener {

    private AnimElement ball;
    private AnimLayer animLayer;

    public static void main(String[] args) {
    Main app = new Main();
    app.start();
    }

    @Override
    public void simpleInitApp() {
    setDisplayStatView(false);
    setDisplayFps(false);

     //set upp screen and animLayer
     Screen screen = new Screen(this);
     screen.setUseMultiTouch(true);
     screen.setUseKeyboardIcons(true);
     animLayer = screen.addAnimLayer("Anim Layer");
     guiNode.addControl(screen);
     
     
     //set up a ball
     ball = new AnimElement(assetManager) {
         @Override
         public void animElementUpdate(float f) {
         }
     };
     ball.setName("ball");
     ball.setTexture(assetManager.loadTexture("Textures/ball.png"));
     ball.addTextureRegion("BallTexture", 0, 0, 64, 64);
     ball.setPosition(100, 100);
     ball.setDimensions(64, 64);
     QuadData q = ball.addQuad("ballQ", "BallTexture", Vector2f.ZERO, Vector2f.ZERO);
     q.getTextureRegion().flip(false, true);
     q.setDimensions(new Vector2f(64, 64));
     ball.setIgnoreMouse(true);
     ball.initialize();
     animLayer.addAnimElement("ballElement", ball);      
     
     //set up input
     inputManager.clearMappings();
     inputManager.addRawInputListener(this);
    

    }

    @Override
    public void simpleUpdate(float tpf) {
    //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
    //TODO: add render code
    }

    public void beginInput() {
    }

    public void endInput() {
    }

    public void onJoyAxisEvent(JoyAxisEvent evt) {
    }

    public void onJoyButtonEvent(JoyButtonEvent evt) {
    }

    public void onMouseMotionEvent(MouseMotionEvent evt) {
    ball.move(evt.getDX(), evt.getDY(), 0);//<-- i want move a ball in any place in screen(when i moving finger on screen)
    }

    public void onMouseButtonEvent(MouseButtonEvent evt) {
    }

    public void onKeyEvent(KeyInputEvent evt) {
    }

    public void onTouchEvent(TouchEvent evt) {
    }
    }
    [/java]

@SetasSan
Ah… I see what the issue is.

You need to enable texture atlasing: (this will increase performance quite a bit as well as stop the error with keyboard icons)

[java]
screen = new Screen(this, “tonegod/gui/style/atlasdef/style_map.gui.xml”);
screen.setUseTextureAtlas(true,“tonegod/gui/style/atlasdef/atlas.png”);
screen.setUseMultiTouch(true);
screen.setUseKeyboardIcons(true);
guiNode.addControl(screen);
[/java]

Also, I’ve updated the Android Test App and put it here:

http://sourceforge.net/projects/tonegodemitter/files/AdroidGUITestApp.rar/download

1 Like

Btw, the AnimElement should already be set up to move for you… just add it to the layer.

You don’t need to handle the events.

And one last side-note…

There was an issue with menu states on Android, I fixed it this morning and is available via the repo or with tonight’s update.

1 Like

than you for help :wink: as always ;D

1 Like

for someone else in future:
first you need to add control and after it setUseKeyboardIcon, otherwise you will get exception

[java]
guiNode.addControl(screen);
screen.setUseKeyboardIcons(true);
[/java]

1 Like
@SetasSan said: for someone else in future: first you need to add control and after it setUseKeyboardIcon, otherwise you will get exception

[java]
guiNode.addControl(screen);
screen.setUseKeyboardIcons(true);
[/java]

Thanks for this. Forgot that the keyboard is completely dependant on the OS… no Android == no keyboard.

Good catch!

I have one more problem, I’m adding bricks in my game (AnimElement objects) in pc i can see them but in android i cant ?
what reason can be for that ?

[java]
private void createStaticBricks(TextureManager textM) {
float widthInPx = width * colWidth;
float heightInPx = height * colHeight;
float bricWidthInPx = width * colWidth / COLS;
float brickHeightInPx = height * colHeight / ROWS;
float startX = (width - widthInPx) / 2;
float startY = (heightInPx) * 1.5f;

    float marginXInPx = width * margin;
    float marginYInPx = height * margin;


    for (int i = 0; i &lt; COLS; i++) {
        for (int ii = 0; ii &lt; ROWS; ii++) {                
            Brick brick = new Brick("Static_Brick_" + i + "/" + ii, startX + bricWidthInPx * i, startY + brickHeightInPx * ii, bricWidthInPx - marginXInPx, brickHeightInPx - marginYInPx, true) {
                @Override
                public void animElementUpdate(float f) {                       
                }
            };               
            animLayer.addAnimElement(brick.getName(), brick);
            allBricks.add(brick);
            
        }
    }

[/java]

[java]
public Brick(String name, float x, float y, float width, float height, boolean destroyable){
super(globals.Instance.assetManager);
this.x=x;
this.y=y;
this.width=width;
this.height=height;
this.destroyable = destroyable;

    TextureManager.Textures texture = TextureManager.Textures.Brick;
    setName(name);
    setTexture(globals.Instance.textureManager.getTexture(texture));
    addTextureRegion("BrickTexture", 0, 0, texture.width, texture.height);
    addTextureRegion("empty", 0, 0, 0, 0);
    setPosition(x, y);
    setDimensions(width, height);

    QuadData q = addQuad("bickQ", "BrickTexture", Vector2f.ZERO, Vector2f.ZERO);
    q.getTextureRegion().flip(false, true);
    q.setDimensions(new Vector2f(width, height));


    setIgnoreMouse(true);
    initialize();
    
}

[/java]

@SetasSan said: I have one more problem, I'm adding bricks in my game (AnimElement objects) in pc i can see them but in android i cant ? what reason can be for that ?

[java]
private void createStaticBricks(TextureManager textM) {
float widthInPx = width * colWidth;
float heightInPx = height * colHeight;
float bricWidthInPx = width * colWidth / COLS;
float brickHeightInPx = height * colHeight / ROWS;
float startX = (width - widthInPx) / 2;
float startY = (heightInPx) * 1.5f;

    float marginXInPx = width * margin;
    float marginYInPx = height * margin;


    for (int i = 0; i &lt; COLS; i++) {
        for (int ii = 0; ii &lt; ROWS; ii++) {                
            Brick brick = new Brick("Static_Brick_" + i + "/" + ii, startX + bricWidthInPx * i, startY + brickHeightInPx * ii, bricWidthInPx - marginXInPx, brickHeightInPx - marginYInPx, true) {
                @Override
                public void animElementUpdate(float f) {                       
                }
            };               
            animLayer.addAnimElement(brick.getName(), brick);
            allBricks.add(brick);
            
        }
    }

[/java]

AnimLayer is a relatively new addition to the library (and still in process). Let me test using it on Android and see if I can figure out the issue.

Out of curiosity, can they be seen if you place them at screen.getWidth()/2, screen.getHeight()/2?

here is whole code, it’s not a lot so it’s not gonna be hard if you need to make test
Test

1 Like

Nope, i cant see them

1 Like

Thanks for the sources… ran it on desktop… looked good. Ran it on android and see what you mean. Give me a few (husband is asking me for something) then I’ll look through the source and see if I can find an issue.

I’m not completely sure, but I think the ball is starting outside the screen range when the app starts on Android. So this may be the case for the bricks as well. Will know in just a bit here.

1 Like

no.jpeg ftw! Made me laugh :wink:

;D that’s good, at least you have fun xD

Ok… I set the position of the Bricks to 0,0 and they are rendering solid black over the stats view.

Now I just need to figure out why they would do this. (Sorry… took me this long just to verify they were there… because I refused to set the viewport background color :wink:

Doh… I know what the problem is. Your images need to be a power of 2 to show up on many mobile devices.

So:

16x16
32x32
64x64
128x128
etc, etc…

This will fix the problem.

2 Likes