Closed Thread Icon

Preserved Topic: Good old setTimeout (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8900" title="Pages that link to Preserved Topic: Good old setTimeout (Page 1 of 1)" rel="nofollow" >Preserved Topic: Good old setTimeout <span class="small">(Page 1 of 1)</span>\

 
Archonian
Nervous Wreck (II) Inmate

From: Sweden, Malmoe
Insane since: Jan 2003

posted posted 10-11-2003 17:36

Y'ello

I've always had and still have problems with setTimeout
(EDIT) or maybe I should use setInterval ? (EDIT)

What I'm trying to do is this:

When someone holds down a key, a gif-animation is suppose to move to the left in 8 pixel steps
The problem is that I dont want this to happen to fast, and there should be like a 200millisecond pause between the little moves. So, while holding down it should move, and as soon as the key is released the movement should stop. And the animation changes into a still image. The change between the images I have no problems with.

I've tried several methods and it always goes down to the problem that it moves in the 8 pixel steps too fast.

Hope you understand my problem and I would be grateful for replys,
Thanks in advance,

Bye

[This message has been edited by Archonian (edited 10-12-2003).]

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-13-2003 10:48

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Archonian
Nervous Wreck (II) Inmate

From: Sweden, Malmoe
Insane since: Jan 2003

posted posted 10-18-2003 15:46

How is onkeypress different from onkeydown ?

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-18-2003 15:53

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Archonian
Nervous Wreck (II) Inmate

From: Sweden, Malmoe
Insane since: Jan 2003

posted posted 10-18-2003 16:07

I get somewhat what you were saying in your first reply but I think I forgot to explain something...
I'm going to move in bigger steps, basically this means that always when moving the object it should always move 16 pixels, BUT in 8 pixel steps. It should finish moving the 16 pxs even if the key is released. Does this make things much more complicated or....

[This message has been edited by Archonian (edited 10-18-2003).]

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-18-2003 16:14

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Archonian
Nervous Wreck (II) Inmate

From: Sweden, Malmoe
Insane since: Jan 2003

posted posted 10-18-2003 16:17

Ok, I basically solved it:

var wTimer;
var frame = 0;
var KEYISDOWN = false;

function keyDown() {
KEYISDOWN = true;
image.src = 'dudeleftwalking.gif';
walkLeft();
wTimer = window.setInterval(checkMove(), 200);
}

function checkMove() {
return walkLeft;
}

function keyUp() {
KEYISDOWN = false;
clearInterval(wTimer);
image.src = 'dudeleft.gif';
}

function walkLeft() {
if (frame < 2) {
image.style.pixelLeft -= 8;
frame++;
setTimeout("walkLeft()",100);
}
else { frame = 0; }
}

document.onkeydown=new Function("if(!KEYISDOWN){keyDown();}");
document.onkeyup=keyUp;


Was this something like what you thought about?
Anyway, thanks a lot for your replys, appreciate it.

[This message has been edited by Archonian (edited 10-18-2003).]

Xgc
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Oct 2003

posted posted 10-18-2003 21:53

You're welcome!

Archonian
Nervous Wreck (II) Inmate

From: Sweden, Malmoe
Insane since: Jan 2003

posted posted 10-20-2003 10:54

Hehe

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-20-2003 10:57

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Archonian
Nervous Wreck (II) Inmate

From: Sweden, Malmoe
Insane since: Jan 2003

posted posted 10-20-2003 20:39

Indeed.

« BackwardsOnwards »

Show Forum Drop Down Menu