微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

调用未定义对象的原型函数

如何解决调用未定义对象的原型函数

我正在尝试为我的新平台游戏制作碰撞函数,但在制作碰撞原型函数时遇到错误

platforms = [];
var newPlatform = function(x,y) {
    this.x = x,this.y = y,this.width = 50,this.height
}
var platform1 = new newPlatform(10,100);
var platform2 = new newPlatform(50,50);
platforms.push(platform1);
platforms.push(platform2);
var player = {
    x:100,y:305,width:80,height:120,veLocity_y:4
}
platforms.prototype.collision = function(player) {
    return (this.x < player.x + player.width && this.x + this.width > player.x && this.y
            < player.y + player.height && this.y + this.height > player.y);
}

for (let i = 0; i < platforms.length; i++) {
    if (platforms[i].collision(player)) {
        player.veLocity_y = 0 ;
    }
}

这给出了一个错误内容为“无法设置未定义的属性'碰撞'”有谁知道如何解决这个问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。