The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 1:59 am

Forum rules


IMPORTANT

This Forum is for Flash related questions ONLY! Do not ask questions about spriting, Game Maker, Photoshop, or anything else not related to Flash.



 [ 3 posts ] 
reduce mega lag ! Tutorial AS2 
Author Message

Joined: Sun Jun 13, 2010 10:41 pm
Posts: 21
Gender: Anime Girl
Hi Im ongokiller50 and I wonna tell you guys how to reduce mega lag.

1st thing in order to reduce serious lag is to "ONLY USE ONE ONENTERFRAME ON THE MAIN TIME LINE, and use it for your hole gameplay!" because OnEnterFrame is very power and can take alot of Fps when there are 5 or more that have alot of scripts in it.

Im gonna teach you how to use One onEnterframe, controlling the ALOT OF players using arrays. array are very power and very useful to detect everything on the stage that you push in the array to move.

3rd avoid "OnClipEvent(enterFrame)" in your game.


lets begin

GamePlay = [];//Created a New Array to control every box in one onenterframe
HowManyBoxes = 100;// HOW Many boxes are we gonna add
onEnterFrame = function(){//checks and do on everyframe;
for (var i = 0; i < HowManyBoxes; i++){// what this does that on every frame;
//on the game "i" is gonna start at 0 and add up to the var HowManyBoxes in one frame.;
//why? because this is to create 200 boxes in one Frame!;
var Boxes = _root.attachMovie("Box","b"+i,i)// this creates what ever name is on the library;
// call "Box" , and name it "b" with what ever number "i" is;
// explain "b1 , b2 , b3";

Boxes._x = random(360)+100;//spawn randomly around 100 - 360;
Boxes._y = random(200)+100;//spawn randomly around 200 - 100;
GamePlay.push(Boxes)// this adds to the array so that we can control it.;
HowManyBoxes--// this is to tell the "for" that this Movieclip(EX:b1,b2) has been;
// created NO NEED TO RE ADD IT again;
};


//CONTROLING THE BOXES;

for (var C = 0; C < _root.GamePlay.length; C++){//this says;
// if "C" is lower than the number "_root.GamePlay.length" (length is how many are they in it by numbers EX: 7);
//then to + add up(C++);
//then on the next frame start with C = 0 again and repeat over and over.;
var ControlBox = _root.GamePlay[C]//_root.GamePlay[C] is a movieClip;
//the "[C]" is a number using the "var C" explain "9";
//this how to control a movieclip;
//inside the array we push in GamePlay, so we useing a var to instead of "_root.GamePlay[C]";
// WHY? Cause its easyer;


//like I said ARRAYS ARE VERY FAST!;
ControlBox._y = ControlBox._y+ControlBox.yspeed//its Y will remain the same;
// but yspeed is in control of its UP AND DOWN YSPEED;

//"ControlBox.yspeed" where using the Box's vars to make him move on its own;
ControlBox.yspeed = ControlBox.yspeed+ControlBox.gravity//ControlBox.yspeed;
//remains the same but gravity is pushing it down;
if (_root.ground.hitTest(ControlBox._x,ControlBox._y+42,true)){;
ControlBox.onground = true;
ControlBox.gravity = 0//stops the gravity form pushing me down when im on the ground;
ControlBox.yspeed =-5//make him jump;
}else{//this mean WHAT IF IM NOT TOUCHING IT?;
ControlBox.onground = false;
ControlBox.gravity = 0.5//gravity contines to push me down;
};
while (_root.ground.hitTest(ControlBox._x,ControlBox._y+40,true)){;// checkes his feet
// THE "WHILE" mean to keep doing it till its no more touching in one frame;
ControlBox._y--//so in one frame its gonna force up to be on top of the ground;
ControlBox.yspeed = 0// " GLICTH FIX "stops my yspeed so that I dont go throw the ground;
};

};
};
// this is how you control alot of movieclips without USING LIKE 5000 ONENTERFRAMES that makes the "pc Crappy to even play" without it breaking a sweat


// as you can see theres 100 MovieClip there WITHOUT NO LAG

Download the EXPLAIN HERE http://www.2shared.com/file/Vf-MsFy0/my_tutorial.html

so yes this is why other ppl flash games lags on your crappy pc. (Because theres more than one "onenterframe".
This is why my game COMBAT TOURNAMENT LAGS ON YOUR PC TOO when
theres 8 ppl fighting (Beucase they all have 2 onenterframes)
And imma upload a updated version on Combat Tournament with bugs fix and lag fix.

My next tutorial I will show you how to make a beat em up game with alot of combos with using the arrows and one attack button


Wed Jan 19, 2011 3:03 am
User avatar

Joined: Fri Jan 02, 2009 6:02 pm
Posts: 7283
Location: Australia
Country: Australia (au)
Gender: Male
MGN Username: Tid
Currently Playing: Deep™ The™ Game™
how to reduce lag when making a flash game in as2
step one stop making it in as2
step two learn as3
step three make it in as3
step four quit school, learn c++
step five make millions of dollars as an indy developer
step six ??????
step seven oh wait we already got profit that's how good this tutorial is

_________________
ImageImageImageImage
Ask me anything!!!
Special thanks to Steven for my beautiful Deep avatar! <3


Wed Jan 19, 2011 4:38 am
WWW

Joined: Sun Jun 13, 2010 10:41 pm
Posts: 21
Gender: Anime Girl
Also "Say like you have a game FULL OF ACTION SCRIPTS AND you DONT want to do it all over again because

you want to reduce MEGA lag."

HINT reducing lag:"more than one onEnterFrame = Serious lag"

Explain: "if you have HP onenterframe and player onenterframe. You can still do this Tutorial"

How do I use one onEnterFrame if I have my game full of onEnterFrames?

I'll show you.

------- TUTORIAL------------
do this
if you have like 20 onEnterframe in your game do this in every onEnterframe

1st thing add on the top of your onEnterFrame "witch needs to be inside movieclip of the player's 1st

frame" why? so you can add multi copys of the same movieclip without rewriting the same code over

and over

_root.ActionStart.push(this)// add this movieClip to a group call "ActionStart" that we
// will create later

then change your "onEnterFrame = function(){" to "startAction = function(){"
-- if you have "onClipEvent(EnterFrame)" -- if you dont skip this
if you have "onClipEvent(EnterFrame)" Copy all the code that "onClipEvent(EnterFrame)" have and past

it inside the 1st frame of moiveclip and replace the intro "onClipEvent(EnterFrame)" into "function =

startAction(){"
--------

now go to MAIN TIME LINE

function = onEnterFrame(){//It does these code on every frame that is about to enter
//thats why its call on Enter Frame "on entering frame"
for (var i = 0; i < _root.ActionStart.length; i ++){//the 1st tutorial i put tells you what
//this does.
var command = _root.ActionStart[i]//we use command that will mean //_root.ActionStart[i]
command.startAction();// what this does, it turns on "function = startAction(){"
// on every frame. think about "OnEnterFrame"(Does it in everyframe then go to the next)
//it commands "command"(MovieClip) to start startAction();
//IF U HADE 20 ONENTERFRAME one every movieClip! U CAN SEE ITS TRANSFORM INTO
// ONE SMALL ONE
}
}
What this does it reduce MEGA LAG

I don't get why this reduces lag?

what the problem is that Flash(your game) stops the game and waits too ALL "onEnterFrame" are Done

and ready to go to the next frame of game witch it causes to slow down. Since We only use one

onEnterframe it will only have to WAIT FOR One ONENTERFRAME to go to the next frame. Causing it to go

alot faster.

So this mean you can add 50 or more movieClips with the game going 80%/100% speed with ALOT OF CODING instead of

20%/100% or lower, and this mean your Slow computer can play it faster.

This is how my new game coming out can run 200 or higher enemys and the 1 player on my
super slow computer at 70%/100% instead of 5%/100 using 201 onenterframes.
BIG SPEED UP RIGHT?

Now Try it on your game and you'll see it will speed up MUCH faster.

http://www.2shared.com/file/PooOTXiB/Bi ... agFix.html


Thu Jan 20, 2011 9:29 pm
Display posts from previous:  Sort by  
 [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.