Jython - Can't access enumerations?

E

Eamonn Rea

Hello! I'm using Jython to write a game with Python/Jython/LibGDX. I wasn'thaving any trouble, and everything was going well, but sadly I can't access items in enumerations.

If you know about the LibGDX library and have used it, you'll probably knowabout the BodyType enumeration for Box2D. I was trying to access the BodyType item in the enumeration. This didn't work, as Jython couldn't find the BodyType enumeration. I asked on the LibGDX forum and no one could help. SoI'm hoping that someone here could help :)

So, is this a problem with LibGDX or Jython? I'm using the latest version of Jython.

Thanks!
 
T

Tim Delaney

Hello! I'm using Jython to write a game with Python/Jython/LibGDX. I
wasn't having any trouble, and everything was going well, but sadly I can't
access items in enumerations.

If you know about the LibGDX library and have used it, you'll probably
know about the BodyType enumeration for Box2D. I was trying to access the
BodyType item in the enumeration. This didn't work, as Jython couldn't find
the BodyType enumeration. I asked on the LibGDX forum and no one could
help. So I'm hoping that someone here could help :)

So, is this a problem with LibGDX or Jython? I'm using the latest version
of Jython.

There is no problems accessing the elements of enumerations with Jython.
The following was tested using Jython 2.7b1:

Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_40
Type "help", "copyright", "credits" or "license" for more information.
import java.util.Collections as Collections
import java.util.Arrays as Arrays

a = Arrays.asList(1, 2, 3)
print(a) [1, 2, 3]
e = Collections.enumeration(a)
print(e) java.util.Collections$2@f48007e

for i in e:
.... print(i)
....
1
2
3

Therefore the problem is either with LibGDX or (more likely) way you are
using it. Please post a minimal example that demonstrates the problem plus
the exact error message you get (I don't know LibGLX at all, but someone
else might, plus trimming it down to a minimal example may reveal the
problem to you).

Tim Delaney
 
E

Eamonn Rea

Ok, here's the code:

body_def = BodyDef() # Imports the BodyDef class fine.

body_def.type = BodyDef.DynamicBody # Says it can't find a module from LibGDX called BodyDef.

All my code:

from com.badlogic.gdx import Game, Gdx, Screen
from com.badlogic.gdx.backends.lwjgl import LwjglApplicationConfiguration, \
LwjglApplication
from com.badlogic.gdx.graphics import OrthographicCamera, GL20
from com.badlogic.gdx.graphics.g2d import SpriteBatch
from com.badlogic.gdx.math import Vector2
from com.badlogic.gdx.physics.box2d import Box2DDebugRenderer, World, BodyDef, \
FixtureDef, PolygonShape

import Player


class Playing(Screen):
def __init__(self):
self.batch = None
self.renderer = None
self.world = None
self.camera = None
self.player = None
self.player_body_def = None
self.player_fixture_def = None
self.player_shape = None


def show(self):
self.batch = SpriteBatch()
self.renderer = Box2DDebugRenderer()
self.camera = OrthographicCamera()
self.player_body_def = BodyDef()
self.player_fixture_def = FixtureDef()
self.player_shape = PolygonShape()

self.world = World(Vector2(0, -9.81), True)

self.player_shape.setAsBox(0.5, 1)

self.player_body_def.fixedRotation = True
self.player_body_def.position.set(0, 0)
self.player_body_def.type = BodyDef.DynamicBody

self.player_fixture_def.density = 1
self.player_fixture_def.friction = 0.5
self.player_fixture_def.shape = self.player_shape
self.player_fixture_def.restitution = 0.01



self.player = Player(self.world, self.player_body_def, self.player_fixture_def)


def resize(self, width, height):
pass


def pause(self):
pass


def resume(self):
pass


def dispose(self):
pass


def render(self, delta):
Gdx.gl.glClearColor(0, 0, 0, 1)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)

self.renderer.render(self.camera.combined, self.world)

BodyDef.DynamicBody is defiantly in the BodyType Enumeration. I've tested it in Java.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top