2D graphics in JME


I want to create a 2D game on JME3 (in a pokémon style, not isometric). Yes I know, it is a 3D game engine, so it wasn’t created for 2D games. I’ve read some topics about, but can you give me some short examples? I tried to create an Image but the constructor wants the image in bytes (and I used to create an Image by its URI/URL in java)… and also how can I animate my sprite? I’ve looked to a SpriteLibrary posted by a jme user, but I don’t understand how to use it! It would be useful use JME canvas? (because the game has 3D and 2D parts…it’s a bit complicated to explain, I hope me and my friends won’t finish too late so I can show you something). Please give me some help, my head’s exploding :slight_smile:

I would highly recommend Slick2D, but if you cannot use that look at making a quad and just putting a texture on it.


You can write 2D games in JME. You’ll fight the engine sometimes and you’ll have to do some things manually that JME already has 3D-ready classes for, but it’s totally doable.

The thing is, it’s not really that much easier than doing it in 3D at that point. You might as well go through the JME tutorials (they would have answered your “how do show an image” question already) and then just try to translate that knowledge into 2D once you have a handle on things. Presuming you don’t want to use something more 2D-dedicated like Slick2D.

There is a spite engine floating around that someone made as well. That might (or might not, depending on what you are doing) be helpful for you…

Can I use slick 2D for 2D engine and JME for 3D engine and merge it all together? (I guess no, but I ask this anyway!)

It is not technologically impossible, but I would not recommend it.

Hello guys I’m proceding with the declaration of a Box shape, geometry, material and texture for my sprite(s), treating them as 2D objects. I haven’t used quad class because when I load an image larger than the screen it loads only a part of it (I’ve tried to move camera but the image remained the same).

Using 3D obj, in a 2D way, instead, it’s almost as easy as working in 3D (of course without jme facilities like animations running etc). Is this a right way, or it’s better to use “plain” classes ( such as quad)? (maybe there are methods for scrolling the maps and other tricks like that!). Sorry for my poor English and thanks for your help.

Quad should work. If it didn’t then you did something wrong.

This is a code sample in jme tutorials :

[java]Geometry geom = new Geometry(“A shape”, mesh); // wrap shape into geometry

Material mat = new Material(assetManager,

“Common/MatDefs/Misc/ShowNormals.j3md”); // create material

geom.setMaterial(mat); // assign material to geometry

// if you want, transform (move, rotate, scale) the geometry.

rootNode.attachChild(geom); [/java]

and this is what I’m doing:


desertGeometry = new Geometry(“desert”, new Quad(10,10);

Material desertMaterial = unshadedMaterial.clone();

desertMaterial.setTexture(“ColorMap”, assetManager.loadTexture(“2DMaps/desert.png”));


rootNode.attachChild(desertGeometry); [/java]

and I don’t see anything. If I put a Box shape( with z = 0) rather than a Quad, all works fine. What I do wrong?

How big was the box?

Note: the quad will run from 0,0 to 10,10 where a Box of width 10 will run from -10, -10 to 10, 10.

Box is defined as follow:

[java]Box desertShape = new Box (new Vector3f(0,0,0), 10f,10f,0);[/java] I also tried to change quad’s x/y but nothing appened…

@andreatucci said:
Box is defined as follow:
[java]Box desertShape = new Box (new Vector3f(0,0,0), 10f,10f,0);[/java] I also tried to change quad's x/y but nothing appened..

With the same material:
[java]new Box (new Vector3f(0,0,0), 10f,10f,0);[/java]

[java]Quad q = new Quad(20,20);
Geometry g = new Geometry(..., q);
g.setLocalTranslation( -10, -10, 0 );

Should look identical from the top. From the bottom the quad will be invisible. Not sure what else might be going wrong in your case.

Ok that’s worked. I had camera issues, thank you!