.hitTestPoint 击中多个测试点 (AS3)
.hitTestPoint hitting multiple test points (AS3)
我可以这样写一个 hitTestPoint 触发器
if (mc1.hitTestPoint(mc2.x, mc2.y, true))
如果我想有多个测试点,我可以写类似
的东西
if (mc1.hitTestPoint(mc2.x, mc2.y, true) || mc1.hitTestPoint(mc2.x-5, mc2.y, true) || mc1.hitTestPoint(mc2.x+5, mc2.y, true))
我想知道是否可以在同一语句中定义多个生命值。我已经尝试过这样的事情但没有运气......
if (mc1.hitTestPoint((mc2.x, mc2.y, true) || (mc2.x, mc2.y, true)))
或
if (mc1.hitTestPoint((mc2.x+5 || mc2.x-5), mc2.y, true))
...还有许多其他方法,但似乎没有任何效果。一遍又一遍地为同一个对象写出新点是一件很痛苦的事情,尤其是当你有 20 多个生命值需要检查时。有没有办法在一个语句中添加多个点?
你似乎混淆了编程和巫术。 DisplayObject.hitTestPoint 按照此指定顺序接受 2 到 3 个指定类型(数字、数字、[可选布尔值])的参数,除此之外别无他法。
((mc2.x, mc2.y, true) || (mc2.x, mc2.y, true)) = single Boolean argument
((mc2.x+5 || mc2.x-5), mc2.y, true) = (Boolean, Number, Boolean)
所以你一次只击中一个点。要命中其中的 20 个,您需要遍历一个点数组。例如:
var Foo:Array =
[
mc2.x, mc2.y,
mc2.x+5, mc2.y,
mc2.x-5, mc2.y
];
// Hit test pairs of elements as (x,y) coordinates.
for (var i:int = 0; i < Foo.length; i += 2)
{
var aHit:Boolean = mc1.hitTestPoint(Foo[i], Foo[i+1]);
if (aHit)
{
trace("Hit!", Foo[i], Foo[i+1]);
}
else
{
trace("Miss!", Foo[i], Foo[i+1]);
}
}
我可以这样写一个 hitTestPoint 触发器
if (mc1.hitTestPoint(mc2.x, mc2.y, true))
如果我想有多个测试点,我可以写类似
的东西if (mc1.hitTestPoint(mc2.x, mc2.y, true) || mc1.hitTestPoint(mc2.x-5, mc2.y, true) || mc1.hitTestPoint(mc2.x+5, mc2.y, true))
我想知道是否可以在同一语句中定义多个生命值。我已经尝试过这样的事情但没有运气......
if (mc1.hitTestPoint((mc2.x, mc2.y, true) || (mc2.x, mc2.y, true)))
或
if (mc1.hitTestPoint((mc2.x+5 || mc2.x-5), mc2.y, true))
...还有许多其他方法,但似乎没有任何效果。一遍又一遍地为同一个对象写出新点是一件很痛苦的事情,尤其是当你有 20 多个生命值需要检查时。有没有办法在一个语句中添加多个点?
你似乎混淆了编程和巫术。 DisplayObject.hitTestPoint 按照此指定顺序接受 2 到 3 个指定类型(数字、数字、[可选布尔值])的参数,除此之外别无他法。
((mc2.x, mc2.y, true) || (mc2.x, mc2.y, true)) = single Boolean argument
((mc2.x+5 || mc2.x-5), mc2.y, true) = (Boolean, Number, Boolean)
所以你一次只击中一个点。要命中其中的 20 个,您需要遍历一个点数组。例如:
var Foo:Array =
[
mc2.x, mc2.y,
mc2.x+5, mc2.y,
mc2.x-5, mc2.y
];
// Hit test pairs of elements as (x,y) coordinates.
for (var i:int = 0; i < Foo.length; i += 2)
{
var aHit:Boolean = mc1.hitTestPoint(Foo[i], Foo[i+1]);
if (aHit)
{
trace("Hit!", Foo[i], Foo[i+1]);
}
else
{
trace("Miss!", Foo[i], Foo[i+1]);
}
}