java脚本bug被捕获的播放器。
idk为什么,但是当我调用功能时,它返回 TypeError TypeError:player.Animate不是功能 尝试了很多事情没有工作 球员。动画是一个函数... idk为什么要这样做。试图调试,但仍然不好。 会喜欢你的帮助。 谢谢 !
const canvas = document.querySelector('canvas');
const c = canvas.getContext('2d');
canvas.width = 1024;
canvas.height = 576;
c.fillRect(0 ,0 , canvas.width, canvas.height);
const gravity = 0.2;
class Sprite {
constructor({position,velocity,height})
{
this.position = position;
this.velocity = velocity;
this.height = height;
}
draw(){
c.fillStyle = 'red';
c.fillRect(this.position.x,this.position.y, 50 , 150 );
}
update(){
this.draw()
this.position.y += this.velocity.y;
this.velocity.y += gravity;
if(this.position.y + this.height + this.velocity.y >= canvas.height){
this.velocity = 0;
}
else {this.velocity.y += gravity;}
}
}
const player = new Sprite({
position :{
x:0,
y:0},
velocity : {
x : 0,
y : 10
}});
const enemy = new Sprite({
position :{
x:400,
y:100},
velocity : {
x : 0,
y : 10}});
console.log(player);
function animate() {
window.requestAnimationFrame(animate);
c.fillStyle('black');
c.fillRect(0,0,c.width,c.height);
player.update();
enemy.update();
}
player.animate();
enemy.animate();
会喜欢你的帮助
idk why but when i call the function it returns Uncaught
TypeError TypeError: player.animate is not a function
tried many things didnt quite work
player. animate is a function... idk why it does that. tried to debug but its still no good.
would love your help.
thanks !
const canvas = document.querySelector('canvas');
const c = canvas.getContext('2d');
canvas.width = 1024;
canvas.height = 576;
c.fillRect(0 ,0 , canvas.width, canvas.height);
const gravity = 0.2;
class Sprite {
constructor({position,velocity,height})
{
this.position = position;
this.velocity = velocity;
this.height = height;
}
draw(){
c.fillStyle = 'red';
c.fillRect(this.position.x,this.position.y, 50 , 150 );
}
update(){
this.draw()
this.position.y += this.velocity.y;
this.velocity.y += gravity;
if(this.position.y + this.height + this.velocity.y >= canvas.height){
this.velocity = 0;
}
else {this.velocity.y += gravity;}
}
}
const player = new Sprite({
position :{
x:0,
y:0},
velocity : {
x : 0,
y : 10
}});
const enemy = new Sprite({
position :{
x:400,
y:100},
velocity : {
x : 0,
y : 10}});
console.log(player);
function animate() {
window.requestAnimationFrame(animate);
c.fillStyle('black');
c.fillRect(0,0,c.width,c.height);
player.update();
enemy.update();
}
player.animate();
enemy.animate();
would love your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论