问题描述
这是一个令人困惑的问题,但这已经困扰着我和我的朋友一段时间了。
因此,我们一直在构建JS画布游戏,还没有太多内容,但是我们试图使主玩家在到达画布底部后不再掉下去。我们基本上已经尝试了一切,这是到目前为止的代码:
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: "probe.0.id": this field cannot be set
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: "probe.1.id": this field cannot be set
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: "probe.2.id": this field cannot be set
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: "probe.3.id": this field cannot be set
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: "probe.4.id": this field cannot be set
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: "probe.5.id": this field cannot be set
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: "probe.6.id": this field cannot be set
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: backend_address_pool.0.fqdns: attribute supports 1 item as a minimum,config has 0 declared
error: azure:network/applicationGateway:ApplicationGateway resource 'appgateway' has a problem: backend_address_pool.0.ip_addresses: attribute supports 1 item as a minimum,config has 0 declared
最受关注的行位于ctx = document.getElementById("myCanvas").getContext("2d");
function drawTri(x1,y1,x2,y2,x3,y3) {
ctx.beginPath();
ctx.moveTo(x1,y1);
ctx.lineTo(x2,y2);
ctx.lineTo(x3,y3);
ctx.fill();
}
class Render_3D_Object {
draw() {
}
}
class PhysicsObject {
constructor(x,y) {
this.velx = 0;
this.vely = 0;
this.accx = 0;
this.accy = 0;
this.accz = 0;
this.x = x;
this.y = y;
}
tick() {
this.x += this.velx;
this.y += this.vely;
if (this.velx > 0) {
this.velx *= 0.85;
}
this.accy -= 0.35;
this.velx += this.accx;
this.vely += this.accy;
if (this.y >= 750) {
if (this.vely/Math.abs(this.vely) == -1){
this.accy *= -0.85;
this.vely *= -0.85;
}
}
}
draw() {
ctx.fillRect(this.x,-1 * this.y,this.width,this.height);
}
}
class Box extends PhysicsObject {
constructor(color,x,y,w,h) {
super(x,y);
this.width = w;
this.height = h;
this.color = color;
}
draw() {
ctx.fillStyle = this.color;
ctx.fillRect(this.x,this.height);
ctx.fillStyle = "black";
}
}
let physicsobjs = [];
let player = new Box("green",20,20);
physicsobjs.push(player);
physicsobjs.push(new Box("black",20))
let movex = 0;
let movey = 0;
let triangle1 = new Render_3D_Object();
function frame() {
ctx.clearRect(0,1000,1000);
player.velx += movex;
player.vely += movey;
for (let obj of physicsobjs) {
triangle1.draw();
obj.tick();
obj.draw();
}
}
setInterval(frame,15);
document.addEventListener("keydown",(ev) => {
if (ev.key == "w")
movey += 0.75 // up
if (ev.key == "s")
movey += -0.75; // down
if (ev.key == "a")
movex += -0.75; // left
if (ev.key == "d")
movex += 0.75; // right
});
document.addEventListener("keyup",(ev) => {
if (ev.key == "w")
movey *= 0.75;
if (ev.key == "s")
movey *= 0.75;
if (ev.key == "a")
movex *= 0.75;
if (ev.key == "d")
movex *= 0.75;
});
中,起始于tick()
,结束于if语句的末尾。
有人可以帮忙吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)