0
Camera
How to make the camera follow a character in a game in pure JavaScript. In general, how to write a camera in js, you can throw examples
13 Answers
+ 1
ŚĄŃ [Exams]
I have my own code in which I tried to make a camera on the line 21 to 60. Can you help me make the camera follow the movement of the red cube
https://code.sololearn.com/W0vuqFS021od/?ref=app
0
Inside ur main loop:
ctx.resetTransform();
ctx.translate(cvs.width/2-red.x, cvs.height/2-red.y);
Translate function translates the origin of the canvas. U can think of translating as adding the specified values to every coordinates u pass to any ctx function. Keep in mind the transformations stack so u need to reset the transform as above.
Here the required translation vector is the vector that points from red's position to the center of the screen.
- 1
ŚĄŃ [Exams] sir
- 1
ŚĄŃ [Exams] u here?
- 1
ŚĄŃ [Exams] very hard code, sir
- 1
ŚĄŃ [Exams] can you explain to me what's what in your code sir
- 1
ŚĄŃ [Exams] How should I do it
- 1
Forgive me sir, I will not call you sir anymore.
- 1
please explain to me how I move the background using my code example😭
https://code.sololearn.com/W0vuqFS021od/?ref=app
- 1
ŚĄŃ [Exams] student, Am I doing everything right? p.s. I made the background black
https://code.sololearn.com/W0vuqFS021od/?ref=app
- 1
ŚĄŃ [Exams] student, did I do everything right? look at my code.
- 1
ŚĄŃ [Exams] school student, Why do I need your example? you have already sent enough examples. I just asked if everything worked out correctly in my code, and if not, why?