Edit Gimp Layers-To-Animation script for BGE

(Admin, I’m not entirely certain this is the most appropriate place to put this thread, so please feel free to change to a more suitable place!)

So I recently watched the tutorials on creating and implementing animated textures by ThaTimst3r and the more recent one by Rosscoe. I’ve given it a go, creating and implementing my own animated texture. I’m really pleased with the results and I really think it’s yet another skill branch worth learning well.

However, there is a slight niggle. There is a script for GIMP, which takes all of your rendered images in separate layers and combines them all in to one sprite sheet. It works really nice without any issue.

but…

As Rosscoe has pointed out in his tutorial, BGE now reads sprite sheets from the bottom, left to right, to top. Before, it was top, left to right, to bottom. So the gimp script will no longer work for BGE.

So I was wondering if anybody would like to take a shot at altering the script slightly to place the images the other way around so that it works for BGE again?

I’ve had a look at it. It’s well commented, and seems reasonably clear, I just can’t really figure out what needs changing and where. ON my next free day, I will take a look and see if I can figure it out, but if somebody want’s to take that burden, I’m not stopping you! :smiley:

Here’s a link to the script:
http://wiki.secondlife.com/wiki/GIMP_Layers_to_SL_Animated_Texture

Tutorial links:
ThaTimst3r: https://www.youtube.com/watch?v=xsU44uFKYEA
Rosscoe Tutorials: https://www.youtube.com/watch?v=AHNraXhKQVc

          ; Crop the layer if necessary so that it fits its
          ; rectangle, and move it to its final position.
          (gimp-layer-resize newlayer
                             newsizex
                             newsizey
                             (- (car offsets) offsetx)
                             (- (cadr offsets) offsety))
          (gimp-layer-set-offsets newlayer (+ framex offsetx) (+ framey offsety))

This part. Basically you have to invert offsetx and offsety. How? No idea, I’ve never seen this language before and I don’t want to learn it anyway.

Yeah I don’t really understand it either.

I did work out a bit of a hack that works though. Thanks to somebody on one of the gimp forums.

-Reverse order of the layers so the last animation frame is first. (Layer -> Stack -> Reverse layer order)
-Run sprite sheet script
-Flip result image horizontally. This is really important otherwise the images will be right-to-left before you do this.

Hello, Merry Christmas!
-[important] ==> Flip each layer Horizontally
-Reverse order of the layers so the last animation frame is first. (Layer -> Stack -> Reverse layer order)
-Run sprite sheet script
-Flip result image horizontally. This is really important otherwise the images will be right-to-left before you do this.

Or use this script, but be care about tiles row size limitation in BGE:
Make a file with name SpriteSheet.scm with this content:

(define (create-sprite-sheet img drawable) 
    (let *  
        ( 
            (anImage 0) 
            (numlayers 0) 
            (layers 0) 
            (imgw 0) 
            (idx 0) 
            (layr 0) 
            (xoff 0) 
        ) 
 
        (set! anImage   (car (gimp-image-duplicate img))) 
        (set! numlayers (car (gimp-image-get-layers anImage))) 
        (set! layers    (cadr(gimp-image-get-layers anImage))) 
        (set! imgw      (car (gimp-image-width anImage))) 
         
        (while (< idx numlayers) 
            (set! layr (aref layers (- (- numlayers 1) idx))) 
            (gimp-layer-translate layr xoff 0) 
            (set! xoff (+ imgw xoff)) 
            (set! idx (+ idx 1)) 
        ) 
         
        (gimp-image-resize-to-layers anImage) 
        (gimp-image-merge-visible-layers anImage EXPAND-AS-NECESSARY) 
        (gimp-display-new anImage) 
    ) 
     
)         
         
(script-fu-register "create-sprite-sheet" 
    _"<Toolbox>/Xtns/Sprite-Sheet/Create From Layers..." 
    "Creates a new image from current image, then offsets each layer of new image, and finally merges all visible layers to create a spritesheet" 
    "[email protected]" 
    "[email protected]" 
    "2009" 
    "INDEXED* RGB* GRAY*" 
    SF-IMAGE        "Image to use"          0 
    SF-DRAWABLE     "Layer to use"          0 
)

I will upload some usefull scripts, soon [After dinner:D].