1

I'm having problems trying to chop sprites out of a sprite map. I can get my first sprite from the top left corner with this:

gdk_pixbuf_composite( sprite_src, sprite_buf,
                      0, 0, sprite_w, sprite_h,
                      0.0, 0.0, 1.0, 1.0,
                      GDK_INTERP_HYPER,
                      255 );

But then I cannot get my second sprite that is just to the right of the first one:

gdk_pixbuf_composite( sprite_src, sprite_buf2,
                      sprite_w, 0, sprite_w * 2, sprite_h,
                      0.0, 0.0, 1.0, 1.0,
                      GDK_INTERP_HYPER,
                      255 );

The first one looks great but I get a black rectangle and a failed assertion on the second one:

GdkPixbuf-CRITICAL **: gdk_pixbuf_composite: assertion 'dest_x >= 0 &&
dest_x + dest_width <= dest->width' failed

I have tried everything I can think of. Any idea what I'm doing wrong?

Also, I don't actually need to do any scaling, but I cannot currently find another way to chop sprites out of a sprite map except using the gdk_pixbuf_composite() function. Is there a better way?

gdonald
  • 984
  • 2
  • 12
  • 23

2 Answers2

0

I assume your destination pixbuf is only sprite_w wide and the sprite should start from 0,0? In that case you also need to translate, otherwise the pixels are copied in the same location as they were in in the original pixbuf.

But the real solution is probably to use gdk_pixbuf_copy_area(): it seems much closer to what you need.

Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54
0

I found gdk_pixbuf_new_subpixbuf, it was exactly what I needed, no scaling, just your basic sprite chopper function:

gdk_pixbuf_new_subpixbuf( sprite_src, sprite_w, 0, sprite_w, sprite_h );
gdonald
  • 984
  • 2
  • 12
  • 23