3 registered members (TedMar, Ayumi, kzhao),
1,359
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Increasing Number Animation
#479103
02/18/20 14:48
02/18/20 14:48
|
Joined: Jan 2012
Posts: 108
gamers
OP
Member
|
OP
Member
Joined: Jan 2012
Posts: 108
|
Hi, I want to prepare an increasing number animation for my GUI. For example, when the user wins a prize, how can I design the reward score as in the animation I shared on the link below? The animation link is here: https://we.tl/t-sCdLe4Bjo3Thank you for your support in advance.
|
|
|
Re: Increasing Number Animation
[Re: gamers]
#479104
02/18/20 15:25
02/18/20 15:25
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hey! I would use digits and would increase variable (containing a number) slowly in a loop. This would result in something very similar to what you showed in the video! Best regards. Edit: this was actually pretty interesting to create (press space to add random value to the main score)
var total_value = 5;
var value_to_add = 5;
var adding_speed = 0.025;
FONT *main_text_font = "Courier#80";
FONT *main_digit_font = "Courier#160";
FONT *add_digit_font = "Courier#64";
PANEL *main_digit_pan =
{
digits(0, 0, "POINTS", main_text_font, 0, 0);
digits(0, 160, "%.0f", main_digit_font, 1, total_value);
flags = SHOW | CENTER_X | CENTER_Y;
}
PANEL *add_digit_pan =
{
digits(0, 0, "%+.0f", add_digit_font, 1, value_to_add);
flags = SHOW | TRANSLUCENT | CENTER_X | CENTER_Y;
}
void add()
{
value_to_add += 5 + integer(random(40));
}
void main()
{
on_space = add;
warn_level = 6;
fps_max = 60;
pan_setcolor(main_digit_pan, 1, 1, COLOR_GREY);
vec_set(&add_digit_pan->blue, vector(0, 211, 255));
var adding_timer = 0;
while(!key_esc)
{
main_digit_pan->pos_x = screen_size.x / 2;
main_digit_pan->pos_y = (screen_size.y / 2) - 160;
add_digit_pan->pos_x = screen_size.x / 2;
add_digit_pan->pos_y = (screen_size.y / 2) + 128;
if(value_to_add > 0)
{
adding_timer += time_frame / 16;
if(adding_timer >= adding_speed)
{
total_value += 1;
value_to_add -= 1;
adding_timer -= adding_speed;
}
add_digit_pan->alpha = 100;
}
if(value_to_add <= 0)
{
add_digit_pan->alpha -= 25 * time_step;
}
wait(1);
}
}
Last edited by 3run; 02/19/20 14:39.
|
|
|
Re: Increasing Number Animation
[Re: gamers]
#479105
02/18/20 15:31
02/18/20 15:31
|
Joined: Oct 2008
Posts: 681 Germany
Ayumi
User
|
User
Joined: Oct 2008
Posts: 681
Germany
|
Hi, you can use a Background Image in a Panel with variable to stay dynamic. The "+63" can be a String or a TEXT* Object, using str_for_num.
var count 0;
PANEL* pan = NULL;
FONT* font = NULL;
void Test()
{
int i;
if(!font) {
font = font_create("Arial#12");
}
if(!pan)
{
pan = pan_create(NULL, 1);
pan.flags |= SHOW;
pan.bmap = bmap_create("YourBackgroundImg.tga");
pan_setdigits(pan, 0,10,10, "Count: %d", font, 1, count);
}
// ...
count = 10;
for(i=0; i < 20; i++);
{
count++;
}
//ptr_remove(font);
// font = NULL;
//ptr_remove(pan.bmap);
// pan.bmap = NULL;
//ptr_remove(pan);
// pan = NULL;
}
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|