Stop draw() function without noLoop() | Sololearn: Learn to code for FREE!
+ 6

Stop draw() function without noLoop()

How can I stop a draw () function without calling noLoop() ? I would like it to run more than one time...

13th Jan 2019, 11:43 PM
Jess
Jess - avatar
12 Answers
+ 6
Check this code on how to stop/start a js animation(start/pause function at line 72): https://code.sololearn.com/Wc5JyXEQUAay/?ref=app
14th Jan 2019, 4:22 PM
Haris
Haris - avatar
+ 4
Check out the start/pause in this code: https://code.sololearn.com/WG1Oc5S07P3t/?ref=app
14th Jan 2019, 2:53 AM
Zeke Williams
Zeke Williams - avatar
+ 4
Thanks Zeke Williams, learned something 😉 however this code seems a bit far from my level ... What i would like to do is to stop an item's growing at some point without requiring user intervention or button... I have tried to add an if statement for my imageSize variable like this : If (imageSize >= 80) { imageSize += 0; } But this attempt dont' work and looks ridiculous but I can't figure out why and what to do ... (Sorry for my hopeless ignorance and bad english 😌)
14th Jan 2019, 11:49 AM
Jess
Jess - avatar
+ 4
Your way is working perfectly, I had to reverse my reasoning. Is it possible that my code isn't working because of the 0 after operator ?
14th Jan 2019, 3:09 PM
Jess
Jess - avatar
+ 4
Thanks Haris, I keep it as a good exemple for the time i'll can write something like this by myself 😉 Hope it's soon !
14th Jan 2019, 5:49 PM
Jess
Jess - avatar
+ 3
Zeke Williams this was my attempt for a khanacademy exercise. It's working there with your suggestion. Now, should I use the void operator to make it work in Sololearn playground ? I'm realy struggling with JavaScript ... thanks you so much for your Care ! https://code.sololearn.com/WYX4K4QqxbJW/?ref=app
14th Jan 2019, 6:40 PM
Jess
Jess - avatar
+ 3
The whole code is here ... From a lesson named JS introduction : draw and animate; Challenge : advertisement. So I'm going on with canvas now ! I'll try to make this work here also. Thanks again, this was very helpful for me 😁
14th Jan 2019, 7:52 PM
Jess
Jess - avatar
+ 3
I'm afraid you're completely right ! Thank you for this super tool, I'm going to fight with or against it 😅 and come back for help I bet ...
14th Jan 2019, 8:22 PM
Jess
Jess - avatar
+ 2
That should work, so I'm not sure why it isn't working for you. You could also try if(imageSize < 80) { imageSize++; } By the way, your English is just fine. If it's still not working, post your code here and I'll take a look at it.
14th Jan 2019, 2:10 PM
Zeke Williams
Zeke Williams - avatar
+ 2
Oh awesome! It could be because of that, but I'm not 100% sure. I'd have to look at the surrounding code first. I'm glad you got it working though!
14th Jan 2019, 3:55 PM
Zeke Williams
Zeke Williams - avatar
+ 2
I haven't used Khanacademy before, but they might be using a set up environment for the drawing and animation JavaScript, meaning that they don't make you write the html or js necessary for the same code to work here in the SoloLearn playground. If that's true, you might need some help, so please feel free to ask. I'll post my template here for canvas animations on SoloLearn too. Good luck Jess https://code.sololearn.com/WXrJwJO19g2P/?ref=app
14th Jan 2019, 8:08 PM
Zeke Williams
Zeke Williams - avatar
+ 1
I'd be interested to see what the Khanacademy exercise is, because I don't see where this would be displayed. Is it a canvas exercise, or did you just copy some of the code and not all of it? I think it should still work here with the suggestion I made.
14th Jan 2019, 6:58 PM
Zeke Williams
Zeke Williams - avatar