image¶
struct image¶
-
struct
image
¶ Images are the visual building blocks of your game. Use images to draw on screen, or as sources for sprites and fonts. Images can be read from a file or created empty and can be used directly or provide frames for sprites or characters for fonts.
The simplest form of creating an image is by using create_image():
struct image* image; image = create_image("path/to/image.png");
Images can also be used as a drawing target instead of the screen:
draw_on_image(image); // draw images, sprites or text draw_on_screen();
You will have to explicitly get rid of any image you create using destroy_image():
destroy_image(image);
Not doing so will result a memory leak.
create_image¶
create_blank_image¶
create_target_image¶
-
struct image *
create_target_image
(int width, int height, struct color color)¶ Create an image that can be used to draw other images or sprites on.
- Return
- image pointer or NULL on failure
- Parameters
width
-The width of the blank image
height
-The height of the blank image
color
-The default color of the target image
destroy_image¶
-
void
destroy_image
(struct image *image)¶ Destroy an image created using create_image() or create_blank_image()
- Parameters
image
-A valid image pointer created using create_image()
draw_image¶
get_image_alpha¶
set_image_alpha¶
set_blend_mode¶
-
void set_blend_mode(struct image * image, enum blend_mode blend_mode)
Set the method to use when drawing an image
- Parameters
image
-image The blend method will work for
blend_mode
-The blend method to apply
load_image¶
Warning
doxygenfunction: Cannot find function “load_image” in doxygen xml output for project “project0” from directory: ../build/doxygen/xml/
cleanup_image¶
-
int
cleanup_image
(struct image *image)¶ Cleanup any initialized image resources Cleanup will free all internally allocated resources for this image, making it ready for deallocation.
- Parameters
image
-Existing image to cleanup
- Note
- You don’t need to use cleanup_image() if you use destroy_image()
- Return
- -1 on error
lock_image¶
-
int
lock_image
(struct image *image, void **pixels, int *pitch)¶ Lock a image to get pixel level access
- Return
- 0 on success or -1 on error
- Parameters
image
-Image to lock
pixels
-pointer reference to the image pixels lock_image() will provide you with
pitch
-pointer to update with the pixel pitch
unlock_image¶
draw_on_image¶
pixels_collide¶
-
int
pixels_collide
(struct image *img1, struct rectangle *rect1, struct image *img2, struct rectangle *rect2)¶ Test if two images have colliding pixels
- Return
- 1 if collision was found 0 if no collisions were found -1 when error occured
- Parameters
img1
-First image to test
rect1
-Area in first image to test
img2
-Second image to test
rect2
-Area in second image to test