I have seen many people using 50-100 images to animate a progress bar, but here i'm using only 3 images and some math:
#include "DragonFireSDK.h"
bool stop = false;
void loading(int p , int MyView, int end_view, int width, int height, int x, int y){
ViewSetVisible(MyView, true);
// p = percent
if(p > 100|| p == 100){
ViewSetxy(MyView, x-(((p-1)*2)-1), y);
ViewSetSize(MyView, width*(p-1), height);
ViewSetVisible(end_view, true);
stop = true;
}
else{
if(p > 50|| p == 50){
ViewSetxy(MyView, x-((p*2)-1), y);
ViewSetSize(MyView, width*(p)+1, height);
}
else{
if(p == 25|| p == 29|| p == 31|| p == 41|| p == 43|| p == 47|| p == 49){
ViewSetxy(MyView, x-((p*2)-1), y);
ViewSetSize(MyView, width*p, height);
}
else{
ViewSetxy(MyView, x-((p*2)-2), y);
ViewSetSize(MyView, width*p, height);
}
}
}
}
int Font, text;
char str[100];
int p;
int x , y ;
int height, width;
int MyView, end_view;
void AppMain()
{
x = 25 , y = 25;
Font = FontAdd("Arial","Regular",12,0xFF0000);
text = TextAdd((x*5)+5, y-2, "Waiting the touch data", Font);
int skin = ImageAdd("Images/prog_menu.png");
ViewAdd(skin, x, y);
int end = ImageAdd("Images/prog_end.png");
end_view = ViewAdd(end, x, y);
ViewSetVisible(end_view, false);
int MyImage = ImageAdd("Images/prog_load.png");
MyView = ViewAdd(MyImage,0, 0);
ViewSetVisible(MyView, false);
height = ImageGetHeight(MyImage), width = ImageGetWidth(MyImage);
}
void AppExit()
{
}
void OnTimer()
{
if(stop == false){
p +=1;
sprintf(str, "%d%%\n", p);
TextSetText(text, str);
}
loading(p , MyView, end_view, width, height, x, y);
}
PS: Download the attachments down below and place them inside your folder: " Images "