好的我需要帮助弄清楚当特技演员与箍碰撞时如何制作它增加一点但是它会多次检测到碰撞并增加5点。谢谢你的帮助。 这是我的代码:
stop();
// Variables to increase money
var totalmoney = 0;
var moneygain:int = 1;
var moneylimit:int = 100000;
//on collision with hoop add 1 point to money
addEventListener(Event.ENTER_FRAME, HoopCollision);
function HoopCollision(event:Event):void
{
if(startstuntman.hitTestObject(starthoop))
{
totalmoney += moneygain;
}
Total.text = totalmoney;
trace("HIT");
}
答案 0 :(得分:0)
最好的办法是 动态添加属性 ,方法是添加:
stop();
var totalmoney = 0;
var moneygain:int = 1;
var moneylimit:int = 100000;
starthoop["hit"] = new Boolean(false); // *** initial is not hit by startstuntman ***
addEventListener(Event.ENTER_FRAME, HoopCollision);
function HoopCollision(event:Event):void
{
if(startstuntman.hitTestObject(starthoop) && starthoop.hit == false) // *** checking additional expression ***
{
totalmoney += moneygain;
starthoop.hit = true; // *** starthoop is now hit, so next time it checks, it wont increase totalmoney because of additional expression***
}
Total.text = totalmoney;
trace("HIT");
}
我希望这会有所帮助,欢呼! 亚历山大。