Documentation de la bibliothèque MLV-3.1.0

advanced/09_animation.c

A ECRIRE

#include <MLV/MLV_all.h>
#include <stdio.h>
#include <stdlib.h>
//
// Attention !
// Pour pouvoir compiler ce programme sous windows et sous macintosh,
// il faut, pour la déclaration du main, respecter strictement la syntaxe
// suivante :
//
int main( int argc, char *argv[] ){
int width = 640, height = 480;
MLV_create_window( "advanced - 9 animation", "animation", width, height );
// On charge les données multimédias en mémoire
const char* file_path_of_creature = "creature.png";
MLV_Image* creature = MLV_load_image( file_path_of_creature );
if( ! creature ){
fprintf(
stderr, "It was impossible to load the file %s.\n",
file_path_of_creature
);
exit(1);
}
const char* file_path_of_sound = "walk.ogg";
MLV_Sound* sound = MLV_load_sound( file_path_of_sound );
if( ! sound ){
fprintf(
stderr, "It was impossible to load the file %s.\n",
file_path_of_sound
);
exit(1);
}
// On construit une animation avec les donnée multimédias
// précédement chargées.
MLV_Animation* animation;
int nb_frames = 6;
int nb_layers = 1;
int nb_channels = 1;
int w = 79, h = 79;
MLV_Image* images[4];
images[0] = MLV_copy_partial_image( creature, 0, 0, w, h );
images[1] = MLV_copy_partial_image( creature, 1*(w+1), 0, w, h );
images[2] = MLV_copy_partial_image( creature, 2*(w+1), 0, w, h );
images[3] = MLV_copy_partial_image( creature, 3*(w+1), 0, w, h );
animation = MLV_create_animation(
nb_frames, nb_layers, nb_channels
);
int layer = 0;
images+0, &sound, 4, animation
);
images+1, NULL, 4, animation
);
images+2, &sound, 4, animation
);
images+3, NULL, 4, animation
);
// Création d'un lecteur d'animation
MLV_Animation_player* animation_player = MLV_create_animation_player( animation );
// On lance la lecture de l'animation
MLV_play_animation_player( animation_player );
// On active le son
MLV_turn_on_sound_of_animation_player( animation_player, 0 );
MLV_change_sound_volume_of_animation_player( animation_player, 0, 0.2 );
// On fice le nombre d'image par seconde
int avance = 0;
int pas = 4;
while(
&touche, NULL, NULL,
NULL, NULL,
NULL, NULL, NULL,
NULL
) == MLV_NONE ||
touche != MLV_KEYBOARD_ESCAPE
){
MLV_update_animation_player( animation_player );
width/2,0, width/2, height, MLV_COLOR_YELLOW
);
avance += pas;
if( avance > width-w ){
MLV_play_revert_animation_player( animation_player );
pas = -pas;
}
if( avance < 0 ){
MLV_play_animation_player( animation_player );
pas = -pas;
}
int position_y = 20;
MLV_draw_image_from_animation_player( animation_player, layer, avance, position_y );
MLV_play_sound_from_animation_player( animation_player, 0 );
}
MLV_free_animation_player( animation_player );
MLV_free_animation( animation );
MLV_free_image( images[0] );
MLV_free_image( images[1] );
MLV_free_image( images[2] );
MLV_free_image( images[3] );
MLV_free_image( creature );
return 0;
}
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012,2013 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
MLV_play_animation_player
void MLV_play_animation_player(MLV_Animation_player *animation_player)
Demare la lecture de l'animation lu par le lecteur d'animation.
MLV_free_audio
void MLV_free_audio()
Ferme proprement les différents périphériques audios.
MLV_add_frame_in_animation
void MLV_add_frame_in_animation(MLV_Image **array_of_images, MLV_Sound **array_of_sounds, unsigned int delay, MLV_Animation *animation)
Ajoute un image dans la séquence d'animation. Cette fonction ne peux pas augmenter le nombre d'image ...
MLV_create_window
void MLV_create_window(const char *window_name, const char *icone_name, unsigned int width, unsigned int height)
Créé une fenêtre dont la taille, et les différents noms sont passés en paramètres.
MLV_update_animation_player
void MLV_update_animation_player(MLV_Animation_player *animation_player)
Met a jour un lecteur d'animation.
MLV_COLOR_BROWN
#define MLV_COLOR_BROWN
Definition: MLV_color.h:1207
MLV_get_event
MLV_Event MLV_get_event(MLV_Keyboard_button *key_sym, MLV_Keyboard_modifier *key_mod, int *unicode, char **texte, MLV_Input_box **input_box, int *mouse_x, int *mouse_y, MLV_Mouse_button *mouse_button, MLV_Button_state *state)
Cette fonction récupère un évènement dans la file d'attente, remplit en fonction de l'évènement récup...
MLV_load_image
MLV_Image * MLV_load_image(const char *file_image)
Charge en mémoire une image contenue dans un fichier.
MLV_Keyboard_button
MLV_Keyboard_button
Énumère l'ensemble des codes des touches du clavier.
Definition: MLV_keyboard.h:50
MLV_Animation_player
struct _MLV_Animation_player MLV_Animation_player
Ce type code un lecteur d'animation.
Definition: MLV_animation.h:290
MLV_NONE
@ MLV_NONE
Definition: MLV_event.h:47
MLV_delay_according_to_frame_rate
void MLV_delay_according_to_frame_rate()
Suspend l'exécution du programme de façon à ce que le temps écoulé depuis le drenier appel à cette fo...
MLV_change_frame_rate
void MLV_change_frame_rate(int rate)
Configure la fréquence de rafraichissement en Hz.
MLV_free_window
void MLV_free_window()
Ferme la fenêtre de la bibliothèque MLV.
MLV_Animation
struct _MLV_Animation MLV_Animation
Ce type code une animation.
Definition: MLV_animation.h:91
MLV_COLOR_YELLOW
#define MLV_COLOR_YELLOW
Definition: MLV_color.h:1069
MLV_draw_image_from_animation_player
void MLV_draw_image_from_animation_player(MLV_Animation_player *animation_player, unsigned int layer, int x, int y)
Dessine à une position donnée l'image actuellement lue par l'animateur. Cette image est situè à une c...
MLV_change_sound_volume_of_animation_player
void MLV_change_sound_volume_of_animation_player(MLV_Animation_player *animation_player, unsigned int channel, float volume)
Change le volume sonore d'un bruitage.
MLV_update_window
void MLV_update_window()
Met à jour l'affichage de la fenêtre.
MLV_free_animation_player
void MLV_free_animation_player(MLV_Animation_player *animation_player)
Libère l'espace mémoire alloué pour un animateur donné.
MLV_draw_filled_rectangle
void MLV_draw_filled_rectangle(int x, int y, int width, int height, MLV_Color color)
Dessine un rectangle plein dont la taille, la couleur et la position du sommet Nord-Ouest sont donnée...
MLV_copy_partial_image
MLV_Image * MLV_copy_partial_image(const MLV_Image *image, int x, int y, int width, int height)
Copie une partie de l'image.
MLV_create_animation_player
MLV_Animation_player * MLV_create_animation_player(MLV_Animation *animation)
Cree un lecteur d'animation et l'initialise avec une animation donnée en paramètre.
MLV_Image
struct _MLV_Image MLV_Image
Définit le type Image dans la bibliothèque MLV.
Definition: MLV_image.h:53
MLV_Sound
struct _MLV_Sound MLV_Sound
Ce type code un échantillon sonore.
Definition: MLV_audio.h:53
MLV_play_sound_from_animation_player
void MLV_play_sound_from_animation_player(MLV_Animation_player *animation_player, unsigned int layer)
Joue le son d'une couche sonore donnée correspondant à l'image en cours de lecture dans l'animation.
MLV_free_animation
void MLV_free_animation(MLV_Animation *animation)
Cette fonction libère les données allouées pour l'animation.
MLV_all.h
Fichier d'entête principal incluant tous les autres fichiers entêtes de la bibliothèque MLV.
MLV_turn_on_sound_of_animation_player
void MLV_turn_on_sound_of_animation_player(MLV_Animation_player *animation_player, unsigned int channel)
Active le son du canal d'un lecteur d'animation donnée.
MLV_clear_window
void MLV_clear_window(MLV_Color color)
Éfface la fenêtre et la remplace par un monochrome de la couleur donnée en paramètre.
MLV_load_sound
MLV_Sound * MLV_load_sound(const char *file_sound)
Charge un ficher contenant un échantillon sonore en mémoire.
MLV_free_image
void MLV_free_image(MLV_Image *image)
Libère la mémoire utilisée par l'image.
MLV_init_audio
int MLV_init_audio()
Cette fonction initialise la bibliothèque MLV pour pouvoir jouer de la musique et des sons.
MLV_create_animation
MLV_Animation * MLV_create_animation(unsigned int nb_frames, unsigned int nb_layers, unsigned int nb_channels)
Créé une animation comportant un nombre d'image donné
MLV_play_revert_animation_player
void MLV_play_revert_animation_player(MLV_Animation_player *animation_player)
Demande à un lecteur d'animation donné de jouer l'animation à l'envers.