[cairo] Blitting and sprites in Cairo

Chris Wilson chris at chris-wilson.co.uk
Wed May 15 02:07:17 PDT 2013


On Wed, May 15, 2013 at 10:47:31AM +0200, Donn wrote:
> How would you move a sprite across a background?
> 
> The sprite could be:
> 
> draw rectangle 32x32
> clip()
> push_group()
> draw sprite with cairo functions
> s=pop_group()
> 
> But now:
> 
> Draw background once
> loop start
>  Copy rect of bg where sprite is gonna go //How do you do this?
>   translate() //move sprite
>   set_source(s)
>   paint() //Draw the sprite
>  //Replace the backdrop
>  ?? //Some kind of set_source + paint again?
> loop
> 
> That kind of jazz.

Assuming you've disposed off the background layer and only have the
frontbuffer left - yes, you would need to make a copy of the area to be
damaged (after undoing the old sprite and before applying the new).

However, since you will want to double-buffer the expose event at least,
you can use that as a composition step and not burn the sprites into the
backdrop.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the cairo mailing list