Lag in Flash?

too many Movie clips make my game lag.

Page 1 of 1

0 Replies - 1020 Views - Last Post: 21 October 2009 - 01:37 PM

#1 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Lag in Flash?

Post icon  Posted 21 October 2009 - 01:37 PM

ok so its basicly a zombie shooter. its at a brids eye view and every 30 seceods more zombies spwan. when theres about 100 zombies (depending on the computer) the game starts to lag. now using the same spawning technique i encounted the same issue but with a much simpler code. it took 1000 balls moving randomly before it started to lag in any way shape or form. now i dont know what the issue is but i do know that my gaming computer(detials will be listed below) hardly handled any better than my laptop(will list also). the only one that fell short of 80 to 100 was my class computer witch though is worse than both of the previous computers shouldnt be doing this. i play flash games of far grater intensity with out any lag. O and it should go with out saying that this shouldnt be lagging. i dont think that it's the computer but i could be wrong so here is a short list.

Gaming Desktop

AMD 9600 quad core 2.3 Ghz
4Gb DDR 800 OCZ ram
2 9800 GTX+ in SLI


Laptop

AMD Truion dual core 2.2 Ghz
4Gb ram ( i dont know what kind)
nivida 6600

Class Computer
i dont any specifics but it's probly like 1 Gb Ram and 4.0 Ghz pentium 4
and some intagrated Graphics card.

Now for some more info on how things work. i have two difrent classes(will be given later). one is the bullet class the other for the zombies. Ok that's all the coding out of the frames so the rest should be some what explanatory.

ok here is frame one Layer one this gives control of you guy (BoxHead) and some other stuff.

stop();
init();
_global.BadGuyNum = 100;
function init() {
Mouse.hide();
BoxHead.left = false;
BoxHead.right = false;
BoxHead.up = false;
BoxHead.down = false;
}
function HitTest() {
	txt2 = _global.BadGuyNum;
	if (_global.BadGuyNum <=0) {
			gotoAndStop("DEAD");
	}
	if (WallX.hitTest (BoxHead._x-10, BoxHead._y, true)) {
			if(BoxHead.left == true) {
			BoxHead._x += 6/4;
			}
	}
	if (WallX.hitTest (BoxHead._x+10, BoxHead._y, true)) {	 
		 	if(BoxHead.right == true) {
			BoxHead._x -= 6/4;
			}
	}
	if (WallY.hitTest (BoxHead._x, BoxHead._y+10, true)) {
			if(BoxHead.down == true) {
			BoxHead._y -= 6/4;
			}
	}
	if (WallY.hitTest (BoxHead._x, BoxHead._y-10, true)) {	 
		 	if(BoxHead.up == true) {
			BoxHead._y += 6/4;
			}
	}
}
BoxHead.onEnterFrame = function() {
	Aimer._y = _root._ymouse;
	Aimer._x = _root._xmouse;
	BoxHead.move();
	checkFace(BoxHead);
	HitTest();
}
function checkFace(thing) {
	tx = Aimer._x - BoxHead._x;
	ty = Aimer._y - BoxHead._y;
	slope = ty / tx;
	rad = Math.atan(slope);
	if(Aimer._x < BoxHead._x) {
	degrees = rad*180/Math.PI-90;
	thing._rotation = degrees;
	}
	if(Aimer._x > BoxHead._x) {
	degrees = rad*180/Math.PI+90;
	thing._rotation = degrees;
	}
}
	
BoxHead.move = function() {
if(Key.isDown(Key.DOWN)) {
	BoxHead.up = false;
	BoxHead.down = true;
	
	BoxHead._y += 6/4;
}
if(Key.isDown(Key.LEFT)) {
	BoxHead.right = false;
	BoxHead.left = true;
	
	BoxHead._x -= 6/4;
}
if(Key.isDown(Key.RIGHT)) {
	BoxHead.left = false;
	BoxHead.right = true;
	
	BoxHead._x += 6/4;
}
	
if(Key.isDown(Key.UP)) {
	BoxHead.down = false;
	BoxHead.up = true;
	
	BoxHead._y -= 6/4;
}
}



Here is Frame one Layer 2

i=0;
_global.j=0;
_global.Dif=1;
wave = 1;
time = 0;
MakeBadGuy();
snd_shoot = new Sound();
snd_shoot.attachSound("greasegun_shoot");
snd_shoot.setVolume(5);
function MakeBadGuy() {
	 while(_global.j<10*wave) {
		_global.j++;
		_root.attachMovie("BadGuy","BadGuy_"+_global.j,10+_global.j);
	}
}
Aimer.onmouseup = function () {
	i=0;
	_root.attachMovie("Bullet","Bullet_"+i,i+1);
	snd_shoot.start();
	_root.BoxHead.gotoAndPlay("shoot");
	
}
function onEnterFrame() {
	AddTime();
	if (time/60 == 30) {
	wave++
	_global.Dif=1.1;
	MakeBadGuy();
	}
	if (time/60 == 60) {
	wave++
	_global.Dif=1.2;
	MakeBadGuy();
	}
	if (time/60 == 90) {
	wave=wave+2;
	MakeBadGuy();
	}
	if (time/60 == 120) {
	wave++
	_global.Dif=1.4;
	MakeBadGuy();
	}
	if (time/60 == 150) {
	wave++
	_global.Dif=1.5;
	MakeBadGuy();
	}
	if (time/60 == 180) {
	_global.Dif=2;
	wave=wave+2;
	MakeBadGuy();
	}
	if (time/60 == 300) {
	_root.gotoAndPlay("Win");
	}
}
function AddTime() {
	time = time + 1;
	txt3 = Math.ceil(time/60);
}




Here is the Bullet Class


class Bullet extends MovieClip {
	var dx: Number;
	var dy: Number;
	var ax: Number;
	var ay: Number;
	var bx: Number;
	var by: Number;
	var Deg: Number;
	var rad: Number;
	var speed: Number;
	function Bullet(){
		GetA();
		_x = _level0.BoxHead._x;
		_y = _level0.BoxHead._y;
	}
		function move(){
			_x += dx/5;
			_y += dy/5;
		}
		function onEnterFrame() {
			CheckHit();
			move();
		}
	function CheckHit() {
	if(_level0.WallY.hitTest(_x,_y,true)) {
		this.removeMovieClip(this);
	}
	 if(_level0.WallX.hitTest(_x,_y,true)) {
		this.removeMovieClip(this);
	}
	}
	function GetA() {
	ax = _level0.Aimer._x;
	ay = _level0.Aimer._y;
	bx = _level0.BoxHead._x;
	by = _level0.BoxHead._y;
	dx = (ax-bx);
	dy = (ay-by);
	}
}



Here is the BoxHead class

class BoxHeadBadGuy extends MovieClip {
	var dx: Number;
	var dy: Number;
	var Dead: Number;
	var Health: Number;
	var Health2: Number;
	var Left:Boolean;
	var Right:Boolean;
	var Up:Boolean;
	var Down:Boolean;
	var tx: Number;
	var ty: Number;
	var slope: Number;
	var degrees: Number;
	var rad: Number;
	var speed: Number;
	var Num: Number;
	function BoxHeadBadGuy(){
		_x = 100;
		_y = 112;
		dx = Math.random()*_global.Dif;
		dy = (Math.random()+0.05)*_global.Dif;
		Health = 100*_global.Dif;
	}
		function move(){
			if(_level0.BoxHead._x > _x) {
			Right = true;
			Left = false;
			_x += dx;
			}
			if(_level0.BoxHead._x < _x) {
			Left = true;
			Right = false;
			_x -= dx-0.05;
			}
			if(_level0.BoxHead._y > _y) {
			Down = true;
			Up = false;
			_y += dy;
			}
			if(_level0.BoxHead._y < _y) {
			Down = false;
			Up = true;
			_y -= dy-0.05;
			}
		}
		function onEnterFrame() {
			move();
			checkB();
			checkFace(this);
			checkWall();
		}
	function checkB() {
	if(_global.BadGuyNum<=0) {
		this.removeMovieClip(this);
	}
	if(_level0.BoxHead.hitTest(this)) {
		_global.BadGuyNum -= 0.5;
	}
	if(_level0.Bullet_0.hitTest(this)) {
		_level0.Bullet_0.removeMovieClip("_level0.Bullet_0");
		checkVH(this);
		Health = Health - 20/_global.Dif;
		_level0.txt = Health;
		if (Health <= 0) {
			this.removeMovieClip(this);
		}
	}
	if(_level0.Wall.hitTest(_x,_y-10,true)) {
		if (Up == true) {
			_y += dy;
		}
	}
	if(_level0.Wall.hitTest(_x,_y+10,true)) {
		if (Down == true) {
			_y -= dy;
		}
	}
	 if(_level0.Wall.hitTest(_x+10,_y,true)) {
		if (Right == true) {
			_x -= dx;
		}
	}
	if(_level0.Wall.hitTest(_x-10,_y,true)) {
		if (Left == true) {
			_x += dx;
		}
	}
	}
	function checkVH(thing) {
	tx = _level0.Aimer._x - _level0.BoxHead._x;
	ty = _level0.Aimer._y - _level0.BoxHead._y;
	slope = ty / tx;
	rad = Math.atan(slope);
	if(_level0.Aimer._x < _level0.BoxHead._x) {
	degrees = rad*180/Math.PI-90;
	speed = Math.sqrt(dx*dx-dy*dy);
	}
	if(_level0.Aimer._x > _level0.BoxHead._x) {
	degrees = rad*180/Math.PI+90;
	speed = Math.sqrt(dx*dx-dy*dy);
	}
	_x += tx/15;
	_y += ty/15;
	}
	function checkFace(thing) {
	tx = _level0.BoxHead._x - _x;
	ty = _level0.BoxHead._y - _y;
	slope = ty / tx;
	rad = Math.atan(slope);
	if(_level0.BoxHead._x < _x) {
	degrees = rad*180/Math.PI-90;
	thing._rotation = degrees;
	}
	if(_level0.BoxHead._x > _x) {
	degrees = rad*180/Math.PI+90;
	thing._rotation = degrees;
	}
	}
	function checkWall() {
		
	}
}



the only thing that is missing are the "DEAD" and "WIN" frames that just tell you you won and have a New Button that starts the game over.

i really want to know how to get rid of this lag i think that the notion that it's the computers is somewhat riduculess but then again i could be wrong. i think it has somthing to do with my extremly slpoy and uncreticed code. that reminds me i want to apolgize for My extremly slopy code and spelling.

This post has been edited by ishkabible: 21 October 2009 - 01:38 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1