0 registered members (),
821
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
while loops and moving imprecisions.
#311883
02/22/10 01:15
02/22/10 01:15
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
Hello. Imagine i want to slide a panel down to the y=200 on the screen. from y=0; i do it: while(panel.pos_y<200){ panel.pos_y+=1*time_step; wait(1); } But sometimes, i check that the final y its not 200, but 199 or something depending on the lag.. How can i avoid that? without the time_step, it gets shaky or slides very quickly. check this little example with dynamic progress bar... And you will se that after a while the panels will overlay, showing a one pixel overlay... Open C file
Last edited by MMike; 02/22/10 02:36.
|
|
|
Re: while loops and moving imprecisions.
[Re: MMike]
#311893
02/22/10 02:33
02/22/10 02:33
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Hello.
Imagine i want to slide a panel down to the y=200 on the screen. from y=0;
i do it: while(panel.pos_y<200){ panel.pos_y+=1*time_step; wait(1); }
But sometimes, i check that the final y its not 200, but 199 or something depending on the lag..
How can i avoid that? without the time_step it gets shaky or slides very quickly. It is very unlikely that panel.pos_y is precisely 200 after the loop. Example: - panel.pos_y is 199.873 - assume that time_step was 0.527 in the last frame - next iteration: while(panel.pos_y<200){ panel.pos_y+=1*time_step; wait(1); } - panel.pos_y is now 200.4 -> end of loop I hope you know what time_step does/ is/ how it is calculated. Otherwise have a look at the manual. Solution: while(panel.pos_y<200){ panel.pos_y+=1*time_step; wait(1); } panel.pos_y = 200;
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: while loops and moving imprecisions.
[Re: MMike]
#311898
02/22/10 02:47
02/22/10 02:47
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
using my example.. and without the time_step to make 199.87 values.. i use this:
//animate progress bar, from 0 to target value:
while(level_fact<1){
pbar.s_graph_r.scale_x=integer(pbar.value*level_fact); //---->>> increase the scale of the repeating bmap piece of pixel width =1 to scale the needed target
pbar.s_graph_cr.pos_x=pbar.s_graph_cl.pos_x+7 //after the start cap piece of 6 pixels plus 1, so its next seamless
+ ( pbar.s_graph_r.scale_x)/2 //DONT KNOW WHY IT NEEDS TO BE /2 or /0.5 ?? but wihout this.. it wont work correct?
; pbar.s_graph_cr.pos_y=pbar.s_graph_cl.pos_y;
level_fact+=0.1;
wait(10 ); //somewhat slow...
}
but it stills overlay at later.. what im missing?
Last edited by MMike; 02/22/10 02:50.
|
|
|
Re: while loops and moving imprecisions.
[Re: MMike]
#311899
02/22/10 02:51
02/22/10 02:51
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
maybe the scaling is giving incorrect pixel sizes on screen, though the number of the scale is corrected displayed
when i scale up something that is 1pixel on _x , and scaling to 2 , i think it will means 2 pixels ...
when scaling to 50, it will means 50 pixels.. and so on too 100..
although the problem on the start is not showing.. only when the scale reaches (probably 70)
Last edited by MMike; 02/22/10 02:55.
|
|
|
Re: while loops and moving imprecisions.
[Re: MMike]
#312057
02/23/10 00:37
02/23/10 00:37
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
i tryed to use the reapeating method of scaling up size_x (that as the manual says will repeat the bmap, which in this case is 1 px lenght... but what i get it a weird effect like spaced repeating bmap... (i think its not a bug)
and from the manual " The panel size is multiplied with the panel scale."
When i use size_x to move the cap panel on the end, to slide with the repeating one.. that size_x is constant..
So Manual is wrong?
Last edited by MMike; 02/23/10 00:41.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|