Information on t0neg0d joystick

Hi there!

I was looking for the place where I can find information on the t0neg0d joystick for android!

Thanks for reading!

[java]
stick = new Joystick(screen, Vector2f.ZERO, (int)size) {
@Override
public void onUpdate(float tpf, float deltaX, float deltaY) {
float dzVal = 0.002f; // Dead zone threshold
if (main.getGame().getActivePlayer() != null) {
// Store the delta to multiply your speed by
main.getGame().getActivePlayer().moveFactor = FastMath.abs(deltaX);
// This stick only evals against x… you can see what to do from this
if (deltaX < -dzVal) {
main.getGame().getActivePlayer().moveLeft = true;
main.getGame().getActivePlayer().moveRight = false;
} else if (deltaX > dzVal) {
main.getGame().getActivePlayer().moveLeft = false;
main.getGame().getActivePlayer().moveRight = true;
} else {
main.getGame().getActivePlayer().moveLeft = false;
main.getGame().getActivePlayer().moveRight = false;
}
}
}
};
// getGUIRegion returns region info “x=0|y=0|w=50|h=50”, etc
stick.setTextureAtlasImage(tex, main.getTextureManager().getGUIRegion(RegionKey.STICK));
stick.getThumb().setTextureAtlasImage(tex, main.getTextureManager().getGUIRegion(RegionKey.THUMB));
// Make the Joystick semi-transparent
stick.getElementMaterial().setColor(“Color”, new ColorRGBA(1,1,1,0.4f));
stick.getThumb().getElementMaterial().setColor(“Color”, new ColorRGBA(1,1,1,0.4f));
screen.addElement(stick, true);
stick.setPosition(padding,padding);
// Add some fancy effects
Effect fxIn = new Effect(Effect.EffectType.FadeIn, Effect.EffectEvent.Show,.5f);
stick.addEffect(fxIn);
Effect fxOut = new Effect(Effect.EffectType.FadeOut, Effect.EffectEvent.Hide,.5f);
stick.addEffect(fxOut);
[/java]

Let me know if this is enough

@t0neg0d

I seem to be having trouble with these lines here

  stick.setTextureAtlasImage(tex, main.getTextureManager().getGUIRegion(RegionKey.STICK));
  stick.getThumb().setTextureAtlasImage(tex, main.getTextureManager().getGUIRegion(RegionKey.THUMB));

I can’t seem to get ahold of that texture manager. In order to access this GUI stuff or the region keys.

Have to head off to bed… but, before I do… I should have specified better:

ignore the getTextureManager crap. the method just requires a Texture and an atlas region string like:

“x=20|y=20|w=120|h=35”

I define all this stuff in a texture manager for my projects so I don’t have to go looking for this stuff when I change out the atlas.

@t0neg0d

I can’t seem to get it to appear on the screen. Here is my method, which is essentially a copy of yours

It initializes okay without any errors and my println is telling me there is indeed a joystick created, but I just can’t see it.

Would this joystick appear on pc also or only on android?

Also, I’ve found something related to the OOM error on the samsung device when it relates to the GUI. When setting the current Value of my indicators I get the out of memory error.

But If I simply initialize and attach the application will run correctly. These indicators also work perfectly on pc, but will not allow themselves to have a value set with android.

For some reason when updating my indicators I run out of memory.

lines 183 and 184 are commented out due to this. Lines 64-98 are the joystick method I tried to set it to the middle of the screen and to show with effect but to no avail

thanks for reading!

Just for testing purposes:

Try showing the joystick without the effect and let me know what happens.
Try setting the indicator current value to 1 instead of 0 and let me know what happens. (Also try 0.001f just because I’m curious)

@t0neg0d

Still no joystick showing up.

But I did get the the indicators to show whatever value I would put.

So it’s something to do with the updating of the indicators.

Here is the stack trace

W/dalvikvm(11124): threadid=12: thread exiting with uncaught exception (group=0x412b1930)
E/com.jme3.app.AndroidHarness(11124): SEVERE Exception thrown in Thread[GLThread 7302,5,main]
E/com.jme3.app.AndroidHarness(11124): com.jme3.renderer.RendererException: An OpenGL error has occurred: out of memory
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.android.RendererUtil.checkGLError(RendererUtil.java:125)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.android.OGLESShaderRenderer.updateBufferData(OGLESShaderRenderer.java:1964)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.android.OGLESShaderRenderer.setVertexAttrib(OGLESShaderRenderer.java:2006)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.android.OGLESShaderRenderer.setVertexAttrib(OGLESShaderRenderer.java:2077)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.android.OGLESShaderRenderer.renderMeshDefault(OGLESShaderRenderer.java:2317)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.android.OGLESShaderRenderer.renderMesh(OGLESShaderRenderer.java:2354)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.material.Material.render(Material.java:1119)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:523)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:322)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:371)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:788)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:719)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:983)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.renderer.RenderManager.render(RenderManager.java:1035)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.app.AndroidHarness.update(AndroidHarness.java:467)
E/com.jme3.app.AndroidHarness(11124): at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:349)
E/com.jme3.app.AndroidHarness(11124): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1524)
E/com.jme3.app.AndroidHarness(11124): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
E/com.jme3.app.AndroidHarness(11124):

Heh! I think I know why your joystick isn’t showing up…

Is your joystick image (“Textures/barrel/D.png”) power of 2? (i.e. 32x32, 64x64, 128x128, 512x512, etc) Quite a few devices won’t render images that are not. Speaking of which I spent an hour trying to figure out why my particle emitter system wasn’t showing correctly on android… this was the reason for that :wink:

As for the indicator… When do you get the error? At value 0? Or any value? Or?

@t0neg0d

The barrel D image is indeed a power of two as it is 128x128!

Also the indicator will crash at any value in the update loop. But will not crash when setting on initialization

@BigBob said: @t0neg0d

The barrel D image is indeed a power of two as it is 128x128!

Also the indicator will crash at any value in the update loop. But will not crash when setting on initialization

Oh… it’s being set in the update loop. I didn’t catch that when looking at the code >.< I should have!

I know that this works fine on Desktop but I have never tried updating it this way on Android (can’t even begin to fathom why it would be different…) Let me go test it and see if I can repro this here on my transformer. In the mean time, try enqueueing the update via a Callable and see if that stops the crash and I’ll work on reproing it and finding the actual problem.

Merp… forgot to ask.

player.firelevel is? An int? float? or?

@t0neg0d

It is an int Im also unsure what enqueueing the update via a Callable means :stuck_out_tongue:

@BigBob said: @t0neg0d

It is an int

Ok… try casting this to a float in the method call:

[java]
ind.setCurrentValue((float)player.firelevel);
[/java]

And let me know if that does it. Or, just change firelevel to a float.

/fingers crossed… if it does, I think you just found my oom issue on Note2, etc.

@t0neg0d

Unfortunately casting it to a float didn’t work either.

I’m also unsure what enqueing with a callable entails, as this is over my head D’=

Side Question: Is the Note2 a samsung device?

@BigBob said: @t0neg0d

It is an int Im also unsure what enqueueing the update via a Callable means :stuck_out_tongue:

um… you would:

[java]
// app is your SimpleApplication
app.enqueue(
@Override
public Object call() {
// Some code you want executed on the next available update loop
return null;
}
);
[/java]

This is useful for updating your scene graph from another thread… but unlikely to help here.

@BigBob said: @t0neg0d

Unfortunately casting it to a float didn’t work either.

I’m also unsure what enqueing with a callable entails, as this is over my head D’=

Side Question: Is the Note2 a samsung device?

Yep yep… one of the couple that is ultra picky… but still really nice.

Ok… I’m going to try a test or three here. casting may not work, however, the method is expecting a float and I’m wondering if this is the reason for the crash. Something is not being handled right on the device (not you… not me… though I should be avoiding whatever it is… and I’m thinking it hass something to do with int to float conversion)

If int to float auto conversion is busted then Java is busted and Android is busted… it’s the most very basic thing right down in the Java language.

So if it’s broken. The world needs to know… abandon all technology and move to a snow cave. :wink:

Did you try changing player.firelevel to a float? Casting may be the entire issue.

I can’t repro the issue on my transformer… I ran this in my update loop and it works. But, thats on this device

[java]
int i = -1;
@Override
public void update(float tpf) {
i++;
ind1.setCurrentValue(i);
if (i >= 100)
i = -1;
}
[/java]

I also changed i to a float with the same results… so my test was not very helpful =(

@pspeed said: If int to float auto conversion is busted then Java is busted and Android is busted... it's the most very basic thing right down in the Java language.

So if it’s broken. The world needs to know… abandon all technology and move to a snow cave. :wink:

This is very specific to certain samsung devices… and it’s not broken… it’s likely a memory leak that is compounding when constantly casting during the update loop.

EDIT: Contrary to popular belief, I am not the only person out there that writes shitty code =P

@BigBob
Oh man… I just read through the joystick code you posted and caught something else. You have the size of the joystick set to 10px x 10px. It’s likely on the screen just not very visible :wink:

EDIT: I’m REALLY sorry for not having caught that earlier >.<