Moving characters | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Moving characters

So, I have created a code to move a character. However is their anyway to improve this. I also want to allow it to react when it touches another object e.g a square on the screen. I have looked it up but it hasn't come up with want I wanted. Could anyone help? Thanks in advance!

1st Jan 2018, 10:11 PM
Zakariya
Zakariya - avatar
5 Answers
+ 1
First it might be easier to keep separation of JS, HTML, and CSS files. That improves the insight to the code. Secondly, what do you mean by 'improve the movement of the character'? Thirdly, sure you just have to optimize collision detection between your letter and the objects. Fourthly, commenting your code improves comprehensibility for others and yourself. I also discovered for myself that I find rarely but sometimes logical errors in my code, just by commenting. The reason for this is that you have to think about how to seperate your code in logical parts for a good documentation/explanation. As my last point I recommend Processing (https://processing.org/) and Daniel Shiffman's Coding Train (https://www.youtube.com/user/shiffman) for further interests in this. Especially the coding train could help you finding the solutions by your own. Which is the most important lecture in programming. The goal sometimes is not only to find a good solution for your issue. Sometimes it's better to learn how to decide, that some solutions will not work on your issue and how you can convert your issue to another, which already has good solutions. I hope even without help on coding, that this answer can satisfy you. Because I think you will find the solution on your own. Especially with the above mentioned resources.
2nd Jan 2018, 12:05 AM
Andreas K
Andreas K - avatar
+ 1
It would simplify everything if you link your code here.
1st Jan 2018, 10:26 PM
Andreas K
Andreas K - avatar
+ 1
Ok. By improving the movement I mean is there anyway to simplify the movement and also putting in images from google as the moving object
2nd Jan 2018, 9:18 AM
Zakariya
Zakariya - avatar
+ 1
You could start rendering your canvas to improve update mechanisms for your canvas. And yes, you can use images in canvases. Here is an example for rendering an animation: http://codetheory.in/rendering-animations-with-moving-objects-on-canvas/ If you get stuck try looking for code snippets on 'Stack overflow' or searching in the web.
2nd Jan 2018, 9:30 AM
Andreas K
Andreas K - avatar
0
1st Jan 2018, 11:45 PM
Zakariya
Zakariya - avatar