Actionscript 3 As3:瓷砖碰撞未点火(flashpunk)
我正在制作的游戏上有以下代码:Actionscript 3 As3:瓷砖碰撞未点火(flashpunk),actionscript-3,types,entity,collision,tile,Actionscript 3,Types,Entity,Collision,Tile,我正在制作的游戏上有以下代码: override public function update():void { var pressed:Boolean = false; if (collide("ground", x, y)) { trace("COLLISION"); } if (Input.check(Key.LEFT)) { xSpe
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();
}
但当玩家触碰地面时,不会检测到碰撞!而玩家却从中摔了一跤!什么是错的?我以为“类型”能让它发挥作用,但我想我错了
if (collide("ground", x, y))
我想你不应该用“x,y”而不是“0,0”,因为这个参数不是用于碰撞的位置,如果我没记错的话,它是作为可选的碰撞偏移量
所以,当你使用x,y作为这个参数时,它可能意味着x+x,y+y作为位置
所以在这里
(collide("ground", x, y + 1))
你应该使用
(collide("ground", 0, 1))
我不确定,但你可以试试这个。你给你的玩家打了一个合适的击键吗?看起来你的Level 1类设置正确,但是你没有包含玩家的hitbox代码 你可以给你的玩家一个基本的命中框,如下所示:
player.setHitbox(64, 64, 0, 0);
player.setHitbox(64, 64, 0, 0);