Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3-使屏幕闪烁半秒_Actionscript 3_Flash_Effects - Fatal编程技术网

Actionscript 3 AS3-使屏幕闪烁半秒

Actionscript 3 AS3-使屏幕闪烁半秒,actionscript-3,flash,effects,Actionscript 3,Flash,Effects,我想做的是: 与[物体]碰撞后,我希望屏幕闪烁约半秒。我尝试了for循环和while循环,但它们似乎不起作用。我不知道该如何编程 自从我制作这个游戏以来,我一直在想如何做到这一点,所以如果有人能帮助我,这将是很有帮助的 谢谢你的阅读。你需要使用一些涉及时间的东西。循环都在一个线程中运行,该线程不会暂停一段时间——这就是它们不工作的原因 下面是如何使用AS3计时器来执行此操作(假设此代码在确定发生冲突后立即运行) 其他方法是使用setInterval、setTimeout、Tweening库和EN

我想做的是:

与[物体]碰撞后,我希望屏幕闪烁约半秒。我尝试了
for循环
while循环
,但它们似乎不起作用。我不知道该如何编程

自从我制作这个游戏以来,我一直在想如何做到这一点,所以如果有人能帮助我,这将是很有帮助的


谢谢你的阅读。

你需要使用一些涉及时间的东西。循环都在一个线程中运行,该线程不会暂停一段时间——这就是它们不工作的原因

下面是如何使用AS3
计时器来执行此操作(假设此代码在确定发生冲突后立即运行)


其他方法是使用
setInterval
setTimeout
、Tweening库和
ENTER\u FRAME
事件处理程序。

一个函数中没有多少内容,我可以放在一个函数中吗?如果你真的想,你可以把它们全部放在一个函数中(对tick和timerDone方法使用内联函数)。是否要我重新编写它,以便将其全部封装到一个函数中?如果您这样做了,那将非常有用,也非常感谢您。确实是这样。调用
flashScreen()
将闪烁屏幕。调整
50
值使其闪烁更快或更慢。非常感谢^u^您的救命恩人。
function flashScreen():void {
    var timer:Timer = new Timer(50, 10); //run the timer every 50 milliseconds, 10 times (eg the whole timer will run for half a second giving you a tick 10 times)

    var flash:Shape = new Shape(); //a white rectangle to cover the whole screen.
    flash.graphics.beginFill(0xFFFFFF);
    flash.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
    flash.visible = false;
    stage.addChild(flash);

    timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void {
        //we've told AS3 to run this every 50 milliseconds

        flash.visible = !flash.visible; //toggle visibility
        //if(Timer(e.currentTarget).currentCount % 2 == 0){ } //or you could use this as a fancy way to do something every other tick
    });

    timer.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:TimerEvent):void {
        //the timer has run 10 times, let's stop this flashing madness.
        stage.removeChild(flash);
    });

    timer.start();
}