Answer the question
In order to leave comments, you need to log in
How to make a js engine?
I started to learn js and wanted to create a 3d engine. But as you know, I didn’t succeed. code
1. How to make it so that I could rotate the camera. When I rotate, as in a 3D game, the element moves in the other direction.
2. How to properly make a cartridge, it is already in the engine, but it’s somehow not like that, it needs to wait until the click and then an object appears.
3. How to make the cartridge not disappear but decrease.
document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var x = 175;
var y = 160;
var r = 30;
var x1 = 3216513;
var y1 = 32131112;
var h = 20;
ctx.fillRect(x, y, 60, 60);
var mouseX = 0;
var mouseY = 0;
canvas.addEventListener("mousemove", setMousePosition, false);
function setMousePosition(e) {
mouseX = e.clientX;
mouseY = e.clientY;
}
function cle(){
ctx.clearRect(0, 0, 400, 350);
}
function draw(){
ctx.fillRect(x1, y1, r, r);
canvas.onmousedown = function(){
x1 = mouseX;
y1 = mouseY;
mouseY;
}
}
function move(){
cle();
draw();
ctx.fillRect(x, y, 60, 60);
x = -mouseX + 390;
}
setInterval(move, 20);
Answer the question
In order to leave comments, you need to log in
1) Cartridge and that's all - these are not elements of the engine. This is game logic. Nefig to shove it into the engine.
2) About the camera - read well, for example, this: https://habr.com/post/319144/.
3) Here is another useful link for you - https://tproger.ru/translations/how-to-learn-gamed...
4) Start with something simpler.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question