yozefx / libgdx-users

Automatically exported from code.google.com/p/libgdx-users
0 stars 0 forks source link

SpriteCache.draw (int cacheID, int offset, int length) can't draw Sprite normally #18

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create several Caches in one SpriteCache
2. Call SpriteCache.draw (int cacheID, int offset, int length) to draw all 
Caches.
3. Call SpriteCache.draw (int cacheID, int offset, int length) to draw all 
Caches with an big length value (eg. 1000).

What is the expected output? What do you see instead?
Screen shall render normally but it not.

What version of the product are you using? On what operating system?
SVN revision 3737. Win XP.

Please provide any additional information below.
Below is my fix FYI.

Index: SpriteCache.java
===================================================================
--- SpriteCache.java    (revision 3737)
+++ SpriteCache.java    (working copy)
@@ -924,8 +924,12 @@
                if (!drawing) throw new IllegalStateException("SpriteCache.begin
 must be called before draw.");

                Cache cache = caches.get(cacheID);
-               offset = offset * 6 + cache.offset;
+               int verticesPerImage = mesh.getNumIndices() > 0 ? 4 : 6;
+               offset *= 6;
                length *= 6;
+               length = Math.min((cache.maxCount / (verticesPerImage * VERTEX_S
IZE) * 6 - offset), length);
+               offset = offset + cache.offset / (verticesPerImage * VERTEX_SIZE
) * 6;
+
                Texture[] textures = cache.textures;
                int[] counts = cache.counts;
                if (Gdx.graphics.isGL20Available()) {

Original issue reported on code.google.com by River2...@gmail.com on 29 Mar 2012 at 10:05