How do i insert an image and animate it using web? will it be possible? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 6

How do i insert an image and animate it using web? will it be possible?

18th Jul 2018, 1:32 AM
SK Sai
SK Sai - avatar
6 Respostas
+ 3
Do it like this: drawImage(element, x, y); The x is how many pixels from the left, and the y from the top. You canā€™t put the URL for element, as it actually needs to be an <img> element: <img src = ā€œSomeURLā€ id = ā€œimageā€/> <canvas></canvas> <script> let ctx = document.getElementsByTagName(ā€œcanvasā€)[0].getContext(ā€œ2dā€); let image = document.getElementById(ā€œimageā€); ctx.drawImage(image, 50, 50); </script> Hope that helps!
18th Jul 2018, 6:19 AM
Rowsej
Rowsej - avatar
+ 6
thanks
19th Jul 2018, 1:21 AM
SK Sai
SK Sai - avatar
+ 5
Use sprites to form the sequential frames, enable them one after another.. https://code.sololearn.com/WFrv82FuZwg2/?ref=app
18th Jul 2018, 3:53 AM
CalviÕ²
CalviÕ² - avatar
+ 1
yes its possible
18th Jul 2018, 1:56 AM
Nura Programmer
Nura Programmer - avatar
18th Jul 2018, 1:59 AM
Nura Programmer
Nura Programmer - avatar
+ 1
You can use the drawImage( ) method. https://www.w3schools.com/tags/canvas_drawimage.asp And yes, animation is also possible. Have a look at this: https://code.sololearn.com/WmP6CuzCPFta/?ref=app
18th Jul 2018, 3:02 AM
777
777 - avatar