简体   繁体   中英

change “speed” for few seconds

So I have an object that moves with "speed" now I set the code that when the object collides with another object the speed of the object decreases. I tried doing so by making the speed change and when the speed changes after 3 seconds change it back to it's original speed.

This is something I tried myself but it doesn't work. Can someone explain me what I am doing wrong, if I'm on the right track or a better way to do this? Thanks in advance

 speed = 10;

 if (c < r0+r1) { 
 lives -=1;

 speed = 5;

 if(speed === 5){
    setTimeout(speed =10 ,3000);
 }
setTimeout(function() {
    speed = 10 
}, 3000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM