Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
New to coding, don’t know how to make the score variable go up each time a sprite is clicked.

What I have tried:

Have tried looking at multiple tutorials but I am still confused.
Posted
Updated 29-Jun-21 5:14am
Comments
[no name] 29-Jun-21 2:28am    
Add a click handler; this example uses mouse over.

https://medium.com/dailyjs/how-to-build-a-simple-sprite-animation-in-javascript-b764644244aa

1 solution

Per Gerry Schmitz's comment, you need to add an event to the sprite. Since it's every time you click it, the suggested onclick event is the obvious choice. But how?

You may wish to start this tutorial from scratch, but here's a direct link to the event hander part: onclick Event[^]

Note that although this uses a <button> element it can be pretty much any element at all.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900