【问题标题】:As3: Tile collision not firing (flashpunk)As3:瓷砖碰撞未触发(闪光朋克)
【发布时间】:2014-03-16 12:59:42
【问题描述】:

我正在制作的游戏中有此代码:

override public function update():void
    {
        var pressed:Boolean = false;

        if (collide("ground", x, y))
        {
            trace("COLLISION");
        }

        if (Input.check(Key.LEFT))
        {
            xSpeed -= power;
            pressed = true;
        }

        if (Input.check(Key.RIGHT))
        {
            xSpeed += power;
            pressed = true;
        }

        if (collide("ground", x, y + 1))
        {
            onTheGround = true;
            ySpeed = 0;

            if (Input.check(Key.UP))
            {
                ySpeed -= jumpPower;
            }
        } else {

            ySpeed += gravity;
        }

        if (Math.abs(xSpeed) < 1 && !pressed)
        {
            xSpeed = 0;
        }

        xSpeed *= hFriction;
        ySpeed *= vFriction;

        adjustXPosition();
        adjustYPosition();
    }

然后我在这个类生成的地图上有一些图块:

public class Level1 extends Entity
{
    private var _tiles:Tilemap;
    private var _grid:Grid;

    public function Level1() 
    {
        _tiles = new Tilemap(Assets.SPRITE_TILESET, 1920, 1080, 120, 120);
        graphic = _tiles;
        layer = 1;

        _tiles.setRect(0, 0, 1920 / 120, 1080 / 120, 1);
        _tiles.setRect(0, 17, 1920 / 120, 1, 0);

        _grid = new Grid(1920, 1080, 120, 120, 0, 0);
        mask = _grid;

        _grid.setRect(0, 17, 1920 / 120, 1, true);

        type = "ground";
    }
}

但是当玩家接触地面时,并没有检测到碰撞!而玩家只是跌倒了!这是什么错误?我以为“类型”会让它起作用,但我想我错了..

【问题讨论】:

    标签: actionscript-3 types entity collision tile


    【解决方案1】:
    if (collide("ground", x, y))
    

    我认为你不应该使用“x,y”而不是“0,0”,因为这个参数不是用于碰撞位置,如果我没记错的话,它是用于可选的碰撞偏移。

    所以,当你使用 x,y 作为这个参数时,它可能意味着 x+x,y+y 作为位置。

    这里,

    (collide("ground", x, y + 1))
    

    你应该使用

    (collide("ground", 0, 1))
    

    我不确定,但你可以试试这个。

    【讨论】:

      【解决方案2】:

      你给你的播放器一个合适的 HitBox 了吗?看起来您的 Level1 类设置正确,但您没有包含播放器的 hitbox 代码。

      你可以像这样给你的玩家一个基本的碰撞箱:

       player.setHitbox(64, 64, 0, 0);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-04-09
        • 1970-01-01
        • 2013-01-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多