Camera | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

10th Apr 2021, 11:03 AM
Alexander Sokolov
Alexander Sokolov - avatar
12 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
10th Apr 2021, 11:26 AM
Alexander Sokolov
Alexander Sokolov - avatar
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.
11th Apr 2021, 8:54 PM
Giorgos
10th Apr 2021, 11:50 AM
Alexander Sokolov
Alexander Sokolov - avatar
- 1
10th Apr 2021, 11:58 AM
Alexander Sokolov
Alexander Sokolov - avatar
- 1
ŚĄŃ [Exams] very hard code, sir
10th Apr 2021, 12:06 PM
Alexander Sokolov
Alexander Sokolov - avatar
- 1
ŚĄŃ [Exams] can you explain to me what's what in your code sir
10th Apr 2021, 12:08 PM
Alexander Sokolov
Alexander Sokolov - avatar
- 1
ŚĄŃ [Exams] How should I do it
10th Apr 2021, 12:09 PM
Alexander Sokolov
Alexander Sokolov - avatar
- 1
Forgive me sir, I will not call you sir anymore.
10th Apr 2021, 12:11 PM
Alexander Sokolov
Alexander Sokolov - avatar
- 1
please explain to me how I move the background using my code example😭 https://code.sololearn.com/W0vuqFS021od/?ref=app
10th Apr 2021, 12:13 PM
Alexander Sokolov
Alexander Sokolov - avatar
- 1
ŚĄŃ [Exams] student, Am I doing everything right? p.s. I made the background black https://code.sololearn.com/W0vuqFS021od/?ref=app
10th Apr 2021, 12:23 PM
Alexander Sokolov
Alexander Sokolov - avatar
- 1
ŚĄŃ [Exams] student, did I do everything right? look at my code.
10th Apr 2021, 1:07 PM
Alexander Sokolov
Alexander Sokolov - avatar
- 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?
10th Apr 2021, 1:22 PM
Alexander Sokolov
Alexander Sokolov - avatar