PDA

View Full Version : delay for a game


kyo
09-19-2002, 03:53 PM
this is a function to control movements in a game ...
function move() {
var x, y;
x = y=0;
if (Key.isDown(Key.RIGHT) == true) {
x = hforce;

this.gotoAndStop("right");
if(this._xscale!=100){
this._xscale=100;
}
omino.play();

}
if (Key.isDown(Key.LEFT) == true) {
x = hforce*-1;

this.gotoAndStop("right");
if(this._xscale!=-100){
this._xscale=-100;
}

omino.play();
.
.
.

what I want is:
if no key is pressed, after 5 seconds the animation goes to a specific frame of the movieclip (in this frame there is the animation of the hero in standby)

I try this code but it doesn't work good ...
if(!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP)){

while(startTime+2000>now){
now=getTimer();
count=true;
}
if(count){
this.gotoAndStop("pausa");
omino.play();

}



someone can help me? :)

thanx in advance!

tg
09-19-2002, 05:46 PM
look at the delaying events in flash tutorial, use the same code in that tutorial, but reset the startTimer variable everytime the user clicks on one of your specified keys.
and once time is up in the enterframe event, have gotoand play 'pause'.

kyo
09-19-2002, 10:24 PM
thankx very much for your help ...
I've only a doubt:
the function is not associated to a movieclip ... and it is only in 1 frame ... please, can you explain me precisely where I have to write the code for delay actions (before function move?) ...
(sorry for my english, I know it isn't good :P ...)
thank you again



:D
:: cheers ::

kyo
09-21-2002, 07:41 AM
http://forum.html.it/forum/faccine/141.gif no answer for me, here?

kyo
09-24-2002, 11:38 AM
http://forum.html.it/forum/images/smilies/quote.gif

kyo
09-27-2002, 08:00 AM
please ... don't forget about me ...
HeLp! :)

tg
09-27-2002, 02:54 PM
ok, since noone has posted for you i'll rough one out for you.


//set a constant that indicates the maximum inactivity allowed
var MAXINACTIVE = 5;//this is seconds
//set function that will check how much time has gone by
checkInactivity=function(){
if(MAXINACTIVE>(getTimer()/1000)-(lastActivityTime()/1000)){
//gotoAndPlay the frame to indicate inactivity
}
};

//everytime a key is pressed, reset lastActivityTime
this.onKeyPress=function(){
lastActivityTime=getTimer()/1000;
};
//everytime the mouse is moved reset lastActivityTime
this.onMouseMove=function(){
lastActivityTime=getTimer()/1000;
};

//check the Activity
setInterval(checkInactivity,MAXINACTIVE);


i haven't tested this, but i think my logic here is ok...

kyo
09-29-2002, 09:45 AM
Wow
thanx very much tg ... you're great! http://forum.html.it/forum/images/smilies/030.gif
I have seen this post today (-> no e-mail informed me ... and I don't know why http://forum.html.it/forum/images/smilies/mmmm.gif )

I'll try it and then I tell you about the result!



:: cheers ::

kyo
09-29-2002, 01:52 PM
ops ... ehm ... it doesn't work maybe 'cause I've flash5 ... and if I'm not in wrong your code is for flashMx, isn't it?
I tried to "adapt" it but my code has failed ...
can you help me again? pleeease http://forum.html.it/forum/images/smilies/fagiano.gif
:)

kyo
10-02-2002, 09:40 AM
http://forum.html.it/forum/images/smilies/014.gif
http://forum.html.it/forum/images/smilies/014.gif

kyo
10-05-2002, 11:18 AM
http://forum.html.it/forum/images/smilies/senzasperanza.gif sigh!