gpt4 book ai didi

flash - Flash AS3从MovieClip访问全局变量

转载 作者:行者123 更新时间:2023-12-01 09:57:34 27 4
gpt4 key购买 nike

我有一个爆炸的影片剪辑,它是用代码完成的,因为我将爆炸的碎片的方向和数量随机化,所以它是一帧的影片剪辑,所有动画都是用代码完成的。问题是,我试图在玩家按下“p”时从主时间轴暂停游戏。现在我有了它,所以它将变量gamePaused = true并调用了函数pauseGame(),该函数将停止所有其他操作。但是我不知道如何从爆炸影片剪辑的代码内部访问变量gamePaused。如果可以某种方式检查影片剪辑中的该变量,则可以暂停该动画,直到播放器再次按下“p”。

因此,基本上,如何从影片剪辑访问主时间轴中的变量?

还要指出的是,所有这些爆炸都是在主时间轴的代码中创建为Sprites的,我在网上找到的所有解决方案都不喜欢。因此,请记住这一点。

这是主要的时间轴代码:

//This Creates An Explosion<br>
function createExplosion(explosionX, explosionY, explosionSize):void{<br>
//This Creates The Explosion Movie Clip
var explosionSprite:Sprite = new Sprite;
addChild(explosionSprite);
var explosionPic:explosionSym = new explosionSym;
explosionSprite.addChild(explosionPic);<br>
<br>
//This Moves It Into Position
if (explosionSize == 3){<br>
explosionSprite.x = explosionX + 15;<br>
explosionSprite.y = explosionY + 15;<br>
}<br>
else if (explosionSize == 2){<br>
explosionSprite.x = explosionX + 5;<br>
explosionSprite.y = explosionY + 5;<br>
}<br>
else if (explosionSize == 1){<br>
explosionSprite.x = explosionX;<br>
explosionSprite.y = explosionY;<br>
}<br>
<br>
//This Starts The Timer
explosion[explosionsOnScreen] = explosionSprite;
explosionTimeLeft[explosionsOnScreen] = 0;
}
//This Removes The Explosions Once Time Is Up
function explosionTimer(evt:TimerEvent):void{
//This Declares The Variables
var M:int = 0;

for (M = 0; M < explosionsOnScreen; M++){
//This Increments The Time
explosionTimeLeft[M]++;

//This Removes The Explosion If Enough Time Has Passed
if (explosionTimeLeft[M] > 15){
explosion[M].parent.removeChild(explosion[M]);
explosion.splice(M, 1);
explosionTimeLeft.splice(M, 1);
explosionsOnScreen -= 1;
break;
}
}
}

//This Creates Bullets To Be Used As Debris
function spawnBullets():void{<br>
//This Declares The Variables<br>
var M:int = 0;<br>

//This Decides How Much Debris Will Appear
randomDebrisNumber = (Math.round(Math.random() * 3) + 3);

for (M = 0; M <= randomDebrisNumber; M++){
//This Spawns The Bullets
var debrisSprite:Sprite = new Sprite;
addChild(debrisSprite);
var debrisBullet:bulletSym = new bulletSym;
debrisSprite.addChild(debrisBullet);

//This Places The Debris
debrisSprite.x = 0;
debrisSprite.y = 0;

//This Adds The Sprite To The Array
debris[M] = debrisSprite;

//This Gets The Direction It Moves
do {
debrisX[M] = ((Math.random() * 2 - 1) * 3);
debrisY[M] = ((Math.random() * 2 - 1) * 3);
} while ((debrisX[M] > -0.1 && debrisX[M] < 0.1) || (debrisY[M] > -0.1 && debrisY[M] < 0.1))
}
}

//This Moves The Debris Away From The Center
function handleMoveDebris(evt:TimerEvent):void{<br>
//This Declares The Variables<br>
var M:int = 0;<br>

//This Increments The Timer
debrisTimerCount++;

if (debrisTimerCount <= 15){
//This Moves The Debris
for (M = 0; M <= randomDebrisNumber; M++){
debris[M].x += debrisX[M];
debris[M].y += debrisY[M];
}
}
else if (debrisTimerCount > 15){
//This Removes the Debris
for (M = randomDebrisNumber; M >= 0; M--){
debris[M].parent.removeChild(debris[M]);
debris.splice(M, 1);
debrisX.splice(M, 1);
debrisY.splice(M, 1);
}

//This Stops The Timer
debrisTimerCount = 0;
timMoveDebris.stop();
}
}

最佳答案

您可以将根强制转换为movieClip,以获取其所有动态属性:

MovieClip(root).gamePaused

一直以来这样写都是很乏味的,因此您可以存储对它的引用:
var top:MovieClip = MovieClip(root);

top.gamePaused

希望有帮助...

关于flash - Flash AS3从MovieClip访问全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5372626/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com