小编Doo*_*man的帖子

HTML5画布中的碰撞检测.优化也

我正在制作平台游戏,但我的碰撞检测有问题.我已经制作了一个在屏幕/地图上绘制图块的功能.在该功能是我的碰撞检测,它只绘制一个瓷砖时工作正常,但当我用三个瓷砖创建"楼梯"时,第一个瓷砖不起作用.玩家只是被"推"到了瓷砖上.侧面检测不起作用.而其他瓷砖工作正常.

这是碰撞检测和瓷砖绘图的代码:

//Function that allows you to draw a tile
function drawTile(type, x, y, collision){
    var tileImg = new Image();
    tileImg.onload = function(){
        ctx.drawImage(tileImg, x, y)
    };
    tileImg.src = "images/" + type + ".png";

    if (collision){
        //Worst collision detection ever.
        if((player_x + player_width == x) && (player_y + player_height > y)){
            canMoveRight = false;
        }else if((player_x == x + 32) && (player_y + player_height > y)){
            canMoveLeft = false;
        }else if((player_y + player_height > y) && (player_x + player_width >= …
Run Code Online (Sandbox Code Playgroud)

javascript html5 canvas collision-detection

1
推荐指数
1
解决办法
3487
查看次数

标签 统计

canvas ×1

collision-detection ×1

html5 ×1

javascript ×1