java脚本bug被捕获的播放器。

发布于 2025-02-04 16:10:53 字数 1663 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文