Sprite blitting


I'm currently porting my cross-platform API to use JME, rather than AWT, so that I can drastically bring down the footprint of the bundled JVM I ship with my games.

Anyway, up till now all the games have been 2D, using bitmap strips containing the sprite animations. I'm planning on emulating sprites by using ortho quads, but I can't seem to find a way of drawing a region from the image strip onto the quad.

To try and make things clearer, say I have a 10x10 pixel sprite, with 10 frames of anim. That's a 10x100 image. Going through the anim, I draw from (0,0) for frame 1, (0,10) for frame 2, and so on.

Has anyone got any advice on how best to do this in JME?

Many thanks :slight_smile:

Ah fantastic! I'll have a rummage through the API now :slight_smile:

Thanks :slight_smile:

OK, I now have a 10x100 quad and I can progress along the strip using setTranslation.

One final thing…

If I then set the quad to be 10x10 (the dimensions of one frame), it resizes the strip to fit into that space.

How can I say "don't resize, clip"…?

You can change the texture coordinates of the quad (setTextureBuffer on the quad), these determine how a texture is mapped on the object

Or you can set the scale of the texture (like setTranslation there's setScale I think), to make it 10 times bigger.


Now on to transparent textures…many thanks for your help Llama :slight_smile:


I posted a simple class to do some Sprite animation in this Thread.  Don’t know if it’ll be any help to you (or if it even still compiles against jME  :P) but there you go.

Thanks for that, I already have a CheekySprite class that I write to, but I'll have a look and see if there's any features worth robbing :slight_smile:

(Transparent textures sorted, I now have a Blobbit sprite animating nicely. Should have it ported by next week and I'll post a link to JME Blobbit Push when I'm done).

OK things are going well, I seem to have cracked the inverted y-axis problem and I'm getting things on the screen!

Now, is there any way of saying "render this quad now" ?

I have a bitmap font class which uses the sprite class. What it does is take each letter in the string, set the corresponding sprite in the sprite strip, and blit it to the screen. Note that it uses the same sprite class - and therefore the same quad - to do this as it progresses.

As you've probably already guessed, all I get on the screen is the last rendered character. All the preceeding renders are ignored.

So, is using a quad / billboard the way to go, or should I start looking into rendering to textures and somehow blitting that instead?

Really all I need is some low-level way to blit directly from a region of the source image to the screen - if I had that I wouldn't need anything else :smiley:

Thanks :slight_smile:

You can force a render using the "OFF" renderqueuemode, but you'll still get the mentioned behavior if you are drawing the quad in the same place each time.  Sounds like you need an animation manager that handles where in the animation you are at a given point in time and assigns the appropriate subtexture to the quad before it is drawn…  but perhaps I do not understand the problem fully.  :slight_smile:

I probably gave too much irrevelant detail there…

I have a Billboard node, containing a Quad, containing a Texture. What I'm trying to do is render one Billboard multiple times, changing the location of the Quad, its local translation and scale each time.

So when I call MyRenderer.draw( myBillboard ), I want it to render immediately, so I can change the properties and render it somewhere else.

What I'm doing is trying to implement Graphics.drawImage(), blitting a section of an image to the screen.

Then setting the queue mode to OFF and calling draw on the Quad should do the trick as that will bypass the queue system and draw it directly to the backbuffer.

How do I set it to OFF? Do you mean SKIP?