【发布时间】:2010-04-28 02:23:42
【问题描述】:
目前我正在开发一个平台类型的游戏。我有一个 for 循环来检查天气或球员的脚是否接触地面。我有这个;
for (i=0; i<5; i++) { //There are 5 floors
if (this.feet.hitTest(_root["g"+i])) {
_root.mc.groundTouch = true; //triggers the mc falling
}
}
只有在其中一个楼层存在时才能正常工作(即,如果 floor1 在舞台上,但 floor2-5 不在);因此,为了尝试反击,我尝试使用;
for (i=0; i<5; i++) {
if (this.feet.hitTest(_root["floor"+i])) {
_root.mc.groundTouch = true; //triggers the mc falling
}
if (!this.feet.hitTest(_root["floor"+i])) {
_root.mc.groundTouch = false;
}
}
这显然行不通,因为要使其正常运行,_root.mc.feet 必须接触所有 5 个“地板”实例。
所以我的问题是;
如果 _root.mc.feet 正在接触任何地板实例,我如何获取代码来制作 _root.mc.groundTouch = true,但要制作 _root。 mc.groundTouch = false 仅当它不接触任何地板实例时?
我知道,如果我真的想这样做,我可以做类似的事情
if (_root.mc.feet.hitTest(_root.floor1) && !_root.mc.feet.hitTest(_root.floor2) && etc)
但为了节省自己的时间,并让自己能够添加楼层而不改变超过 i 到我拥有的楼层数量,我更喜欢更简单的方法,希望有所作为带有 for 循环。
提前感谢您的帮助,非常感谢您的帮助
【问题讨论】:
标签: actionscript actionscript-2