[cairo] can you divide the surface into "tiles"?
spk121 at yahoo.com
Tue Apr 30 07:13:31 PDT 2013
> From: marco ferrari <pacomako at gmail.com>
>I'm a student working for an university project and I'm fairly new to the "cairo world", sorry if my question may seem trivial to you but I cannot find an answer in the documentation (and the fact that english is not my first language didn't help at all).
>I'm trying to create a graphical interface for a simple 2d videogame and I need a simple and pratical way to represent the game's world.
>My idea was to create a .png image of the world then load it into a gtk window, then if something changes in the game (for example the character moves) recreate the .png image with the newer information and reload it in the window and so on.
I did something like this once. Here's what I ended up with
Create a gtk_drawing_area.
Create an ARGB32 cairo_surface_t which is the same size as your
drawing area. This is the 'double buffer'.
Create a cairo_t context from the double buffer surface.
Do two steps: 'present' and 'render'
For each sprite or tile you want to draw...
- Create a cairo_surface_t the size of the sprite and copy your
sprite data into it.
- cairo_set_source_surface the sprite onto the double buffer
- cairo_paint the sprite surface onto the double buffer context
in the right location
- destroy the sprite cairo_surface_t
- Use gdk_cairo_context on your gtk_drawing_area to get a cairo_t
of the actual screen
- cairo_set_source_surface the double buffer surface onto the
- cairo_paint the double buffer onto the screen
- destroy the actual screen context
I don't know if this is the best way, but, it works for me.
More information about the cairo