Closed Thread Icon

Preserved Topic: Faster then settimeout('move',1); Pages that link to <a href="https://ozoneasylum.com/backlink?for=18077" title="Pages that link to Preserved Topic: Faster then settimeout(&amp;#039;move&amp;#039;,1);" rel="nofollow" >Preserved Topic: Faster then settimeout(&#039;move&#039;,1);\

 
Author Thread
Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-12-2001 17:56

Is it posible to get "settimeout('move',1)" to go faster then this
withdout changin the step of the objekt

exsample

document.fire.style.pixelLeft-= 1; //step
Time = setTimeout('move()',1); //speed



Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-12-2001 21:26

Technically, that code should move it so fast that in one second, it would go across the entire screen of a 1024x768 maximized window.

So, you see, the problem is most likely the fact that your code itself is taking a long time to run. What you need to do is optimize the code to be as fast as possible. And, realistically, you *will* have to change the step size if you want it to be faster.

But, if there's more to that function than you've showed us already, why don't you show us the entire function? That way we can help you make it run as fast as possible.

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-12-2001 22:24

This is the intair function.

function move()
{
if (g==1)
{eval(doc+"fire"+sty+"pixelLeft+= 1");}
else
{eval(doc+"fire"+sty+"pixelLeft-= 1");}

Time = setTimeout('move()',r);

t=t+1; b=y;


if (g==1) {if (t>250) {y=y+1;}}
if (g==1) {if (b==1) {y=0; r=r+2; }}
if (g==1) {if (t==300) { clearTimeout(Time); g=2; r=1; t=1;}}

if (g==2) {if (t>250) {y=y+1;}}
if (g==2) {if (b==1) {y=0; r=r+2; }}
if (g==2) {if (t==300) {clearTimeout(Time); g=1; r=1; t=1;}}

if (x==1) {clearTimeout(Time); x=2; Time = setTimeout('move()',r);
}}

function setup()
{
document.all.fire.style.pixelLeft=10;

}

</script>

i made this just to learn more about javascript and d-html.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-12-2001 22:55

Yar moving stuff 1 pixel at a time is a CPU hog.

The only way to get the same sort of effect faster is to change the size of the step.
It can easily be done with out losing the smoothness of the effect the only trick can be stopping it at nice intervals



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-12-2001 22:59

Hmmmm, nice intervals, what is that??

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-12-2001 23:07

Ummm not really anything in particular.

Usually I write these functions so that they take 5px steps however. this is going to be a problem if I want something to stop at like 127. since you are going to 250 you shouldn't have a problem




:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-12-2001 23:11

ok, no that not a problem just set the "=" to ">"

Well i have a nother problem, this function is runing on a layer cald fire, now if i want to run it on fire1,2,3 and 4

how do i do this

YOUREanHTML
Nervous Wreck (II) Inmate

From: Pa, US
Insane since: Aug 2001

posted posted 08-13-2001 08:30

dont know if this is relevant, but if I know where my object is gonna start and finish, I like to make the computer decide the step size for me. All I have to know is how many steps (speed) I want it to make to get from start to finish, and it also gets rid of that pesky endpos-overshooting thing.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-13-2001 14:31

The problem is, if you want it to go exactly, say, 61 pixels in five steps, there's no whole number step that can do that! What you can do, though, is keep track of the object's exact position in a separate variable.

numsteps = 5;
maindist = 61;
step = maindist/numsteps;

step will now contain some decimal number. Now, instead of constantly adding that step to the object's left position, add it to some other variable:

leftpos = 0;

function move()
{
leftpos += step;
// now set the object's left position to leftpos.
}

So, even though the object's left position is always an integer, it will be rounded from the variable leftpos. So, the object will end up moving 12 pixels the first step, then 12 again, then 13, then 12, then 12.

Hope that made sense...

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-13-2001 14:38

Thanks, everyone



[This message has been edited by Osaires (edited 08-13-2001).]

[This message has been edited by Osaires (edited 08-13-2001).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-13-2001 18:50

Ah, yes, forgot your question, Osaires. You would use a for loop:

for (a=0; a < 4; a++)
{
if (g==1)
{eval(doc+"fire"+a+sty+"pixelLeft+= 1");}
else
{eval(doc+"fire"+a+sty+"pixelLeft-= 1");}
}

Notice the +a's in there.

Note that you'll be doing this to fire0, 1, 2, and 3, not one through four. (starting with zero works out easier in the long run.)

Now, if you want g, r, and t to behave separately for each of the layers, you'll have to use an array for each variable, and more for loops.

« BackwardsOnwards »

Show Forum Drop Down Menu