我正在制作一个《传说之下》的伤害系统,但我就是做不好。这段代码有什么问题? 冲击波和灵魂是 FlxSprites。
var point1:FlxPoint = FlxPoint.weak(blaster.x, blaster.y + 104 * blaster.scale.y);
var point2:FlxPoint = FlxPoint.weak(blaster.x + blaster.width, blaster.y + blaster.height - 140 * blaster.scale.y);
var blasterMidpoint:FlxPoint = FlxPoint.weak(blaster.getMidpoint().x, blaster.getMidpoint().y);
var soulhit1:FlxPoint = FlxPoint.weak(soul.x, soul.y);
var soulhit2:FlxPoint = FlxPoint.weak(soul.x + soul.width, soul.y + soul.height);
var hitbox:FlxRect = new FlxRect.fromTwoPoints(point1, point2);
var hitboxSoul:FlxRect = new FlxRect.fromTwoPoints(soulhit1, soulhit2);
hitbox.getRotatedBounds(blaster.angle, blasterMidpoint, hitbox);
我尝试使用这段代码,期望它工作得很好,但它碰巧让碰撞箱完全错误,因为它实际上位于精灵下方,角度为 0。(当我将爆能器的角度设置为 0 时,它可以工作)冲击波有一个角度,碰撞箱甚至低于某个点,就好像冲击波的角度为 0
我认为碰撞箱位置是错误的
final hitboxBlasterRatio:Int = blaster.width * 0.5; //adjust
final hitboxRatio:Int = soul.width * 0.5;
final bCornerUp:FlxPoint = FlxPoint.weak(blaster.x + blaster.width / 2 - hitboxBlasterRatio / 2, blaster.y + blaster.height / 2 - hitboxBlasterRatio / 2);
final bCornerDown:FlxPoint = hitboxBlasterRatio + blaster.width / 2 + hitboxRatio / 2, blaster.y + blaster.height / 2 + hitboxBlasterRatio / 2);
final sCornerUp:FlxPoint = FlxPoint.weak(soul.x + soul.width / 2 - hitboxRatio / 2, soul.y + soul.height / 2 - hitboxRatio / 2);
final sCornerDown:FlxPoint = FlxPoint.weak(soul.x + soul.width / 2 + hitboxRatio / 2, soul.y + soul.height / 2 + hitboxRatio / 2);
final hitboxBlaster:FlxRect = new FlxRect.fromTwoPoints(bCornerUp, bCorderDown);
final hitboxSoul:FlxRect = new FlxRect.fromTwoPoints(sCornerUp, sCorderDown);
hitbox.getRotatedBounds(blaster.angle, blaster.getMidpoint(), hitboxBlaster);
尝试一下