Sprite animation

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Sprite animation

    Hello Segger community,

    I used the bitmap converter to create an animated sprite from a gif file.
    The .c file looks good, I got the picture data for 8 images, 1 array with delays between the pictures, a color and a log palette, a storage and a bitmap array. This is the usage proposal generated by the converter:

    C Source Code

    1. * Usage:
    2. * extern const GUI_BITMAP * apbmPicture[8];
    3. * extern const unsigned aDelayPicture[8];
    4. * GUI_SPRITE_CreateAnim(apbmPicture, 10, 10, 0, aDelayPicture, GUI_COUNTOF(apbmPicture));

    If I use this as proposed, the sprite is created successfully, but the function GUI_SPRITE_StartAnim fails. I suggest this is because the array aDelayPicture should have a length of GUI_COUNTOF(apbmPicture)-1 ?


    Here is what I tried to make GUI_SPRITE_StartAnim work:

    C Source Code

    1. const unsigned aDelayPicture[7] = {100, 100, 100, 100, 100, 100, 100};
    2. GUI_HSPRITE hSprite = GUI_SPRITE_CreateAnim(apbmPicture, 40, 40, 0, aDelayPicture, 8);
    3. int error=0;
    4. if (hSprite==0)
    5. error=1;
    6. error=GUI_SPRITE_SetLoop(hSprite, 1); //repeat infinitely
    7. GUI_SPRITE_Show(hSprite);
    8. error=GUI_SPRITE_StartAnim(hSprite);

    As I call the function GUI_SPRITE_CreateAnim with a period of 0, the sprite is created successfully.
    StartAnim succeeds, but only the first of the eight pictures is displayed. This is what I expected to happen, because the period to be used to switch between the images is zero. As soon as I increase this value the function GUI_SPRITE_CreateAnim fails.

    Can someone help me by providing information about which problems GUI_SPRITE_CreateAnim and GUI_SPRITE_StartAnim can encounter? Is this how GUI_SPRITE_StartAnim shall be used (start animation once and pictures are switched automatically?) or does it require to be called periodically?

    Thank you very much in advance!
    Greetings!

    Edit:
    emWin V5.22 is used

    The post was edited 1 time, last by Val-R ().

  • Hello,

    I did not experience any problem when using the following code:

    C Source Code

    1. #include "GUI.h"
    2. extern const GUI_BITMAP * apbm[18];
    3. extern const unsigned aDelay[18];
    4. void MainTask(void) {
    5. GUI_Init();
    6. GUI_SPRITE_CreateAnim(apbm, 10, 10, 0, aDelay, GUI_COUNTOF(apbm));
    7. while (1) {
    8. GUI_Delay(100);
    9. }
    10. }
    Display All

    Best regards,
    Adrian
  • Hello Adrian,

    I missed calling GUI_Exec or GUI_Delay in order to update the display frequently. Neither did I expect the animation to work without using GUI_SPRITE_StartAnim.

    Thank you very much for providing your example code. It works fine for me.

    Kind regards!