Re: cairo: multiple sprites images in one PNG



Le 15 mars 2012, Christopher Howard a écrit :

Question for the veterans:

----------
ship_surf = cairo_image_surface_create_from_png("ship.png");
// ...
cairo_set_source_surface (cr, ship_surf, x, y);
cairo_paint (cr);
----------

But what if I want, for ease of maintainability (and less system I/O
calls) to put a whole bunch of sprites in one PNG? Is it possible for me
to either...

* load one PNG image into a surface, and then draw to a CR using only a
small part of that surface?

or

* load one PNG into a surface, and then split that surface into multiple
smaller surfaces?

I'm no veteran, but I'd create one small cairo_t per sprite, then repeat your last two lines above (where cr would be the sprite), once for each sprite, with appropriate x and y : Cairo will automatically clip what falls outside the sprite's cairo_t.

(Your first option seems feasible with clipping, but might be more complicated: you'd need to clip each time you draw the sprite.)

--
Lucas Levrel



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]