I would like to use jme for making a 2D game, so I need to create sprites. Typically, a sprite is a Quad with Texture on it. So far so good. My questions are:
1.- What would be a good (regarding performance) way to realize animations? Right now, I have a sprite that has different textures for each animation frame. During an update, the correct texture will be selected by calling setRenderState(). In a different posting I read that normally a sprite would have only one texture including all different frames and during an update only the texture coordinates would be adjusted. Is this possible in jme? How would I do that?
2.- Basically, all I want in a 2D game is to have the sprite images appear the same as I created them with my graphics tool. What would you suggest as the general scene setting? So far, I don’t use lights or MaterialState and the sprite texture has FM_NEAREST filtering. Can I make a typical 2D game with that approach, or do I miss something important?
I hope my questions are not too basic/impresise. Any hint regarding jme and 2D games is appreciated. Thanks in advance!
Regarding only having one texture that includes all the animation states, take a look at the hud tutorial in the wiki: http://www.mojomonkeycoding.com/pmwiki/index.php/Tutorials/HUDsForTheTotalNoob
I know it sounds strange, but take a look at the “Displaying dynamic values in the hud section”. It describes how to cut out only a part of an image, and applying it to a quad.
I know it sounds strange, but take a look at the "Displaying dynamic values in the hud section". It describes how to cut out only a part of an image, and applying it to a quad.
Great, thank you Per, this solves the texture coordinates issue :D
Now I only have to get my sprite images unmodified into the game. I tried a couple of things, but the sprite texture still looks a little blurred when I put it on a Quad. I'm trying to figure the correct settings out for letting each pixel of the texture appear exactly the same as the original image without any filtering or similar modifications.
Obviously, I need to learn more OpenGL...
Blurring is probably due to mipmapping being turned on. Do not use mipmapping and it should be ok.
It could also be that your Quad is larger than the texture you’r applying to it, so that it gets stretched out (see the thread I posted earlier today in this section).
How do I turn mipmapping off? When I use
TextureManager.loadTexture(
image,
Texture.MM_LINEAR,
Texture.FM_LINEAR,
false));
it has no effect. I looked in the source code, and for me it seems that the isMipmapped flag is never used.
If I try
TextureManager.loadTexture(
image,
Texture.MM_NONE,
Texture.FM_LINEAR,
false));
I get an error:
org.lwjgl.opengl.OpenGLException: Invalid value (1281)
at org.lwjgl.opengl.Util.checkGLError(Unknown Source)
at org.lwjgl.opengl.Display.update(Unknown Source)
at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(LWJGLRenderer.java:453)
at com.jme.app.BaseGame.start(BaseGame.java:74)
at test.HudTutorial.main(HudTutorial.java:42)
@Per: my Quad has the exact same size as the texture.
The texture has the correct outline, but the pixel colors are a little blurred.
TextureManager.loadTexture(
image,
Texture.MM_NONE,
Texture.FM_LINEAR,
false));
Should work. I'll look into it.
TextureManager.loadTexture(
image,
Texture.MM_NONE,
Texture.FM_LINEAR,
false));
Should work. I'll look into it.
Did you find out anything yet?
Sorry, baegsi. This fell through the cracks…
To not use Mipmapping create a texture like:
TextureManager.loadTexture(
image,
Texture.MM_LINEAR,
Texture.FM_LINEAR,
false));
This will use the texture as is at every distance.