Web instantiate object at touch | Sololearn: Learn to code for FREE!

+1

Web instantiate object at touch

I am trying to instantiate particles by touching the screen. I am trying to adapt the code below but no success. Can anyone point me in the right direction? What else do I need? function mousePressed() { boxes[boxes.length] = new Box(mouseX, mouseY, 25, 25); }

7/5/2020 8:02:45 PM

bell

4 Answers

New Answer

+3

If boxes is an array, then use the push() method instead …… boxes.push(new Box(………… )); … .

+1

Please provide the whole code, if you don't mind

+1

Mirielle [INACTIVE] I got it! I am so happy, please, find attached the code. I was missing the right event listener and a loop to read in particles on touch. https://code.sololearn.com/WUfP4hA5osiH/?ref=app as you may see, you were acknowledged because I got a lot from your newton conservation of moment code (funny you ansewered my question, you were already credited in the code I posted early on today, movers02). now I can thank you directly!

0

Mirielle [INACTIVE] Thank you! I have done that but still nothing happens. I must be missing something listening to the event? I am reading a long article on touch events but if you have a code where this works, I would be grateful to see an example.