В настоящее время я работаю над небольшим флэш-приложением в качестве дополнительного трюка для работы (как 2D художник).Это был первый раз, когда я и мой друг взялись за программирование со вспышкой, уже отмечая, что флэш как движок и AS3 иногда немного специфичны.
Файл флэш-памяти отстает, но мы не можемвыяснить проблемы, вызывающие отставание.Для графики используются в основном фотошоп, обработанные png и несколько файлов иллюстраторов для хитбоксов.
Сам код:
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.utils.Timer;
import flash.events.TimerEvent;
{ /* MAIN */
stop();
stage.focus = stage;
var initDone: Boolean
if (!initDone) {
// stop all movie clips that have more than 1 frame
stopMovieClips(chair, credits, cup, cvinv, doll, hat, kaktus, karpfen, karpfenhit, laptop, log, luke1, luke3, mini, paper, pickles, portfolio, portfolioinv, poster, pylon, rkcard, smoke, sylvanas, talk_long, talk_short, textbox, trash, triforce, trophy, worbla);
// mask all hitboxes transparent
setMovieClipsTransparent(chairhit, cuphit, cvinvhit, dollhit, hathit, kaktushit, karpfenhit, laptophit, lukehit, minihit, portfolioinvhit, paperhit, pickleshit, posterhit, pylonhit, rkcardhit, sylvanashit, trashhit, triforcehit, trophyhit, worblahit);
// set hitboxes inactive
setMovieClipsInactive(cvinvhit, portfolio, pickleshit, portfolioinvhit, rkcardhit, triforcehit);
// mask other movie clips transparent
setMovieClipsTransparent(cvinv, log, luke3, pickles, portfolio, portfolioinv, rkcard, talk_long, talk_short, triforce);
//start background animations
//talk_standard.gotoAndPlay(1);
//set initialization as done
trace("Initialization completed.");
initDone = true;
}
}
{ /* EVENT LISTENER */
{ /* INFLATE OBJECTS ON MOUSEOVER */
chairhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(chair, textbox, "chair", talk_long, talk_standard));
cuphit.addEventListener(MouseEvent.MOUSE_OVER, inflate(cup, textbox, "cup", talk_long, talk_standard));
cvinvhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(cvinv, textbox, "cvinv", talk_long, talk_standard));
dollhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(doll, textbox, "doll", talk_long, talk_standard));
hathit.addEventListener(MouseEvent.MOUSE_OVER, inflate(hat, textbox, "hat", talk_short, talk_standard));
kaktushit.addEventListener(MouseEvent.MOUSE_OVER, inflate(kaktus, textbox, "kaktus", talk_short, talk_standard));
karpfenhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(karpfen, textbox, "karpfen", talk_short, talk_standard));
laptophit.addEventListener(MouseEvent.MOUSE_OVER, inflate(laptop, textbox, "laptop", talk_long, talk_standard));
//lukehit.addEventListener(MouseEvent.MOUSE_OUT, inflate(luke, textbox, "luke", null, null));
minihit.addEventListener(MouseEvent.MOUSE_OVER, inflate(mini, textbox, "mini", talk_short, talk_standard));
paperhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(paper, textbox, "paper", talk_long, talk_standard));
portfolioinvhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(portfolioinv, textbox, "portfolioinv", talk_long, talk_standard));
pickleshit.addEventListener(MouseEvent.MOUSE_OVER, inflate(pickles, textbox, "pickles", talk_long, talk_standard));
posterhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(poster, textbox, "poster", talk_long, talk_standard));
pylonhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(pylon, textbox, "pylon", talk_short, talk_standard));
rkcardhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(rkcard, textbox, "rkcard", talk_long, talk_standard));
sylvanashit.addEventListener(MouseEvent.MOUSE_OVER, inflate(sylvanas, textbox, "sylvanas", talk_long, talk_standard));
trashhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(trash, textbox, "trash", talk_short, talk_standard));
triforcehit.addEventListener(MouseEvent.MOUSE_OVER, inflate(triforce, textbox, "triforce", talk_short, talk_standard));
trophyhit.addEventListener(MouseEvent.MOUSE_OVER, inflate(trophy, textbox, "trophy", talk_short, talk_standard));
worblahit.addEventListener(MouseEvent.MOUSE_OVER, inflate(worbla, textbox, "worbla", talk_long, talk_standard));
}
{ /* DEFLATE OBJECTS ON MOUSEOUT */
chairhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(chair, textbox, talk_long, talk_standard));
cuphit.addEventListener(MouseEvent.MOUSE_OUT, deflate(cup, textbox, talk_long, talk_standard));
cvinvhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(cvinv, textbox, talk_long, talk_standard));
dollhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(doll, textbox, talk_long, talk_standard));
hathit.addEventListener(MouseEvent.MOUSE_OUT, deflate(hat, textbox, talk_short, talk_standard));
kaktushit.addEventListener(MouseEvent.MOUSE_OUT, deflate(kaktus, textbox, talk_short, talk_standard));
karpfenhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(karpfen, textbox, talk_short, talk_standard));
laptophit.addEventListener(MouseEvent.MOUSE_OUT, deflate(laptop, textbox, talk_long, talk_standard));
//lukehit.addEventListener(MouseEvent.MOUSE_OUT, deflate(luke, textbox, null, null));
minihit.addEventListener(MouseEvent.MOUSE_OUT, deflate(mini, textbox, talk_short, talk_standard));
paperhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(paper, textbox, talk_long, talk_standard));
pickleshit.addEventListener(MouseEvent.MOUSE_OUT, deflate(pickles, textbox, talk_long, talk_standard));
portfolioinvhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(portfolioinv, textbox, talk_long, talk_standard));
posterhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(poster, textbox, talk_long, talk_standard));
pylonhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(pylon, textbox, talk_short, talk_standard));
rkcardhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(rkcard, textbox, talk_long, talk_standard));
sylvanashit.addEventListener(MouseEvent.MOUSE_OUT, deflate(sylvanas, textbox, talk_long, talk_standard));
trashhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(trash, textbox, talk_short, talk_standard));
triforcehit.addEventListener(MouseEvent.MOUSE_OUT, deflate(triforce, textbox, talk_short, talk_standard));
trophyhit.addEventListener(MouseEvent.MOUSE_OUT, deflate(trophy, textbox, talk_short, talk_standard));
worblahit.addEventListener(MouseEvent.MOUSE_OUT, deflate(worbla, textbox, talk_long, talk_standard));
}
{ /* ADD TO INVENTORY ON MOUSE CLICK */
paperhit.addEventListener(MouseEvent.CLICK, addToInventory(portfolioinv, portfolioinvhit));
laptophit.addEventListener(MouseEvent.CLICK, addToInventory(triforce, triforcehit));
hathit.addEventListener(MouseEvent.CLICK, addToInventory(pickles, pickleshit));
chairhit.addEventListener(MouseEvent.CLICK, addToInventory(rkcard, rkcardhit));
posterhit.addEventListener(MouseEvent.CLICK, addToInventory(cvinv, cvinvhit));
}
{ /* TIMED LISTENERS */
var randomBlockLuke: Boolean;
var randomTimerLuke: Timer = new Timer(60 * 1000) // start INITIAL animation after set time (in milliseconds)
randomTimerLuke.start();
randomTimerLuke.addEventListener(TimerEvent.TIMER, randomTimedAnimation(luke1, randomTimerLuke, 20000, 45000, randomBlockLuke));
}
{ /* SPECIAL LISTENERS */
var karpfenExchanged: Boolean = false;
var kawarimiSound: kagebunshin = new kagebunshin();
//var karpfenRevertTimer: Timer = new Timer(0);
karpfenhit.addEventListener(MouseEvent.CLICK, kawarimi(karpfen, smoke, log, karpfenhit, 13, karpfenExchanged, /*karpfenRevertTimer,*/ kawarimiSound));
//karpfenRevertTimer.addEventListener(TimerEvent.TIMER, kawarimi(karpfen, karpfenhit, smoke, log, karpfenhit, 13, karpfenExchanged, karpfenRevertTimer, kawarimiSound));
var clickcounterLuke: uint = 0;
lukehit.addEventListener(MouseEvent.CLICK, multiObjectAnimation(luke1, randomBlockLuke, clickcounterLuke, true, luke3));
trashhit.addEventListener(MouseEvent.CLICK, function () {
credits.gotoAndStop("credits")
});
credits.addEventListener(MouseEvent.CLICK, function () {
credits.gotoAndStop("normal")
});
//titlescreen.titlebutton.addEventListener(MouseEvent.CLICK, closepopup(titlescreen));
}
}
{ /* FUNKTIONEN */
function inflate(mc1: MovieClip, mc2: MovieClip, textpos: String, mcStartAnim: MovieClip = null, mcStopAnim: MovieClip = null): Function {
return function (e: MouseEvent): void {
mc1.gotoAndStop("bump");
mc2.gotoAndStop(textpos);
if (mcStartAnim != null) {
mcStartAnim.alpha = 1;
if (mcStopAnim != null) {
mcStopAnim.alpha = 0;
mcStopAnim.gotoAndPlay(0);
};
mcStartAnim.addFrameScript(mcStartAnim.totalFrames - 1, lastFrameReached);
mcStartAnim.gotoAndPlay(1);
function lastFrameReached(): void {
mcStartAnim.gotoAndStop(1);
if (mcStopAnim != null) {
mcStartAnim.alpha = 0;
};
};
};
};
};
function deflate(mc1: MovieClip, mc2: MovieClip, mcStopAnim: MovieClip = null, mcStartAnim: MovieClip = null): Function {
return function (e: MouseEvent): void {
mc1.gotoAndStop("normal");
mc2.gotoAndStop(1);
if (mcStopAnim != null) {
mcStopAnim.gotoAndStop(1);
if (mcStartAnim != null) {
mcStartAnim.gotoAndPlay(1);
mcStartAnim.alpha = 1;
mcStopAnim.alpha = 0;
};
};
};
};
function kawarimi(mcBefore: MovieClip, mcAnim: MovieClip, mcAfter: MovieClip, mcHit: MovieClip, exchangeFrame: int = -1, statusExchanged: Boolean = false, /*timerRevert: Timer = null,*/ mcAnimSound: * = null): Function {
var blocked: Boolean = false;
var instance: MovieClip = this;
return function (e: MouseEvent): void {
if (!blocked) {
blocked = true;
var mcBeforeTmp: MovieClip;
var mcAfterTmp: MovieClip;
var mcHitFrame: uint;
if (statusExchanged) {
mcBeforeTmp = mcAfter;
mcAfterTmp = mcBefore;
mcHitFrame = 2;
} else {
mcBeforeTmp = mcBefore;
mcAfterTmp = mcAfter;
mcHitFrame = 1;
}
/*
if (timerRevert != null) {
timerRevert.stop();
};
*/
//setMovieClipsInactive(mcBeforeHitTmp);
//mc2.x = mc1.x - mc1.width/2 - mc2.width/2;
//mc2.y = mc1.y + mc1.height/2 + mc1.height/2;
mcAnim.addFrameScript(mcAnim.totalFrames - 1, lastFrameReached);
if (exchangeFrame < 0) {
exchangeFrame = 1;
} else if (exchangeFrame >= mcAnim.totalFrames) {
exchangeFrame = mcAnim.totalFrames;
};
mcAnim.addFrameScript(exchangeFrame - 1, exchangeAssets);
mcAnim.gotoAndPlay(2);
if (mcAnimSound != null) {
mcAnimSound.play();
};
function lastFrameReached(): void {
mcAnim.gotoAndStop(1);
/*
if (!statusExchanged && timerRevert != null) {
timerRevert.delay = 10000;
timerRevert.repeatCount = 1;
timerRevert.start();
trace("Timer started");
}
*/
statusExchanged = !statusExchanged;
blocked = false;
};
function exchangeAssets(): void {
mcBeforeTmp.alpha = 0;
mcAfterTmp.alpha = 1;
mcHit.gotoAndStop(mcHitFrame);
};
};
};
};
function setMovieClipsTransparent(...listMC): void {
for each(var mc: MovieClip in listMC) {
mc.alpha = 0;
};
};
function stopMovieClips(...listMC): void {
for each(var mc: MovieClip in listMC) {
mc.stop();
};
};
function setMovieClipsInactive(...listMC): void {
for each(var mc: MovieClip in listMC) {
mc.mouseEnabled = false;
mc.mouseChildren = false;
};
};
function setMovieClipsActive(...listMC): void {
for each(var mc: MovieClip in listMC) {
mc.mouseEnabled = true;
mc.mouseChildren = true;
};
};
function addToInventory(mcObj: MovieClip, mcHit: MovieClip): Function {
return function (e: MouseEvent): void {
mcObj.alpha = 1;
setMovieClipsActive(mcHit);
}
}
function randomTime(minTime: uint, maxTime: uint): uint {
var range: uint = maxTime - minTime;
var Time: Number = Math.ceil(Math.random() * range) + minTime;
return (Time);
};
function randomTimedAnimation(mc1: MovieClip, timer: Timer, minTime: uint, maxTime: uint, blockObject: Boolean = true): Function {
return function (e: TimerEvent): void {
if (!blockObject) {
blockObject = true;
mc1.addFrameScript(mc1.totalFrames - 1, lastFrameReached);
mc1.gotoAndPlay(1);
function lastFrameReached(): void {
mc1.gotoAndStop(1);
var interval: uint = randomTime(minTime, maxTime);
timer.delay = interval;
trace("Timer for " + mc1.name + " started with " + interval + " milliseconds.");
blockObject = false;
};
};
};
}
function multiObjectAnimation(mc1: MovieClip, blockObject: Boolean = true, clickcounter: uint = 0, onlyif: Boolean = true, ...listMC): Function {
var blocked: Boolean = false;
return function (e: MouseEvent): void {
if (!blocked) {
blocked = true;
blockObject = true;
if (clickcounter >= listMC.length - 1) { // if all elements have been iterated once...
clickcounter = 0; // ...then reset clickcounter and start from anew.
trace("Resetted click counter for " + mc1.name + ".");
};
mc1.gotoAndStop(1);
listMC[clickcounter].gotoAndStop(1);
mc1.alpha = 0;
listMC[clickcounter].alpha = 1;
listMC[clickcounter].addFrameScript(listMC[clickcounter].totalFrames - 1, lastFrameReached);
listMC[clickcounter].gotoAndPlay(1);
function lastFrameReached(): void {
listMC[clickcounter].gotoAndStop(1);
mc1.gotoAndStop(1);
mc1.alpha = 1;
listMC[clickcounter].alpha = 0;
clickcounter += 1;
trace("Set click counter for " + mc1.name + " to: " + clickcounter + ".");
blocked = false;
blockObject = false;
};
};
};
};
function gotoFrame(mc1: MovieClip, frameLabel: String, alpha: int = -1): Function {
return function (e: MouseEvent): void {
if (alpha >= 0) { // only change alpha is a value is specified in function call
mc1.alpha = alpha;
};
switch (frameLabel) {
case "previous":
if (mc1.currentFrame == 1) {
mc1.gotoAndStop(mc1.totalFrames);
} else {
mc1.gotoAndStop(mc1.currentFrame - 1);
};
break;
case "next":
if (mc1.currentFrame == mc1.totalFrames) {
mc1.gotoAndStop(1);
} else {
mc1.gotoAndStop(mc1.currentFrame + 1);
};
break;
case "first":
mc1.gotoAndStop(1);
break;
case "last":
mc1.gotoAndStop(mc1.totalFrames);
break;
default:
mc1.gotoAndStop(frameLabel);
break;
};
};
};
};
Игра на моей странице: https://www.schwarzsarah.com/flash Flashfile на GoogleDrive, так как игра на странице вызывает проблемы: https://drive.google.com/open?id=1SnsX-LULbFCGdqTJWkzqkhe7Ie5qCZOR
Согласно Adobe Scout, команды goToAndPlay потребляют больше всего энергии, но даже после их отключения ничего не изменилось.
Что нужно помнить о графике и коде?
Aзаранее большое спасибо за любую возможную помощь.