Forums → Programming Forum → Flash MX 2004: Lag problem. Help plese
2 | 4862 |
I recently strated creating a RPG game in Flash MX 2004 AS2.0 and when I start my game after 3-5min it starts lagging. Any tips? thanx code:
//_root
function rollover(who2, text2) {
timer = 1;
countdown = function () {
timer--;
if (timer == 0) {
textbox.text = "";
clearInterval(countdownInterval);
}
};
countdownInterval = setInterval(countdown, 1000);
if (_root.cursor.hitTest(who2)) {
textbox.text = text2;
}
}
function visible(who) {
if (who._x>layer._x+300 || who._x<layer>layer._y+300 || who._y<layer>
who._visible = false;
} else {
who._visible = true;
}
}
//end root
[/code]
//player
onClipEvent (load) {
var speed = 5;
var oldspeed = speed;
var health = 200;
var maxHealth = health;
_root.shot._visible = false;
var selected = 0;
shotcount = 1;
rad = 0.0174532925199433;
moving = false;
}
onClipEvent (enterFrame) {
_root.textbox._x = this._x-250;
_root.textbox._y = this._y-270;
_root.textbox.selectable = false;
if (moving) {
moving = true;
this.gotoAndStop(2);
mcx = _x-m.x;
mcy = _y-m.y;
_rotation = -Math.atan2(mcx, mcy)/rad;
mr = _rotation*rad;
if (Math.sqrt((mcx*mcx)+((mcy)*(mcy)))>speed) {
_y -= speed*Math.cos(mr);
_x -= -(speed*Math.sin(mr));
} else {
_x = m.x;
_y = m.y;
moving = false;
this.gotoAndStop(1);
}
}
if (Key.isDown(Key.SHIFT)) {
this.gotoAndStop(1);
moving = false;
myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
myDegrees = Math.round((myRadians*180/Math.PI));
_root.yChange = Math.round(_root._ymouse-this._y);
_root.xChange = Math.round(_root._xmouse-this._x);
this._rotation = myDegrees+90;
}
if (Key.isDown(Key.SHIFT) && (moving=true)) {
moving = false;
}
// helti
_root.health.bar._xscale = (health/maxHealth)*100;
if (health<=0) {
health = 0;
_root.health.bar._xscale = 0;
_root.hptext = 0;
}
}
onClipEvent (mouseDown) {
moving = true;
m = {x:_root._xmouse, y:_root._ymouse};
if (Key.isDown(Key.SHIFT) && this.selected == 0) {
moving = false;
_root.shot.duplicateMovieClip("shot"+shotcount, shotcount+7000);
_root["shot"+shotcount]._visible = true;
shotcount++;
if (shotcount>100) {
shotcount = 1;
}
}
if (Key.isDown(Key.SHIFT) && this.selected == 1) {
moving = false;
_root.li.duplicateMovieClip("li"+shotcount, shotcount+7000);
_root["li"+shotcount]._visible = true;
shotcount++;
if (shotcount>100) {
shotcount = 1;
}
}
}
// end player
//shot
onClipEvent (load) {
var attack = 5;
if (this._name == "li" {
this._visible = false;
} else {
this._visible = true;
}
this._x = _root.player._x;
this._y = _root.player._y;
this._rotation = _root.player._rotation;
shotxspeed = 20*Math.sin(_root.player._rotation*(Math.PI/180));
shotyspeed = 20*Math.cos(_root.player._rotation*(Math.PI/180));
}
onClipEvent (enterFrame) {
_root.visible(this);
this._x += shotxspeed;
this._y -= shotyspeed;
if (_root.player._x-220>this._x || this._x>_root.player._x+200) {
unloadMovie(this);
}
}
//end shot
//cursor
onClipEvent (enterFrame) {
startDrag(_root.cursor_move, true);
Mouse.hide();
}
onClipEvent (mouseDown) {
if (!Key.isDown(Key.SHIFT)) {
_root.player.moving = true;
duplicateMovieClip(this, "as2", 0);
_root.as2.gotoAndPlay(2);
Mouse.hide();
}
}
onClipEvent (mouseUp) {
Mouse.hide();
}
//end cursor
//spider
onClipEvent (load) {
var hp = 10;
}
onClipEvent (enterFrame) {
_root.visible(this);
_root.rollover(_root.spider2, "sta"
_root.rollover(this, ["Spider lvl. 1 hp:"+hp+"/10"]);
if (hp == 0) {
unloadMovie(this);
}
xdist = Math.round(_root.player._x-this._x);
ydist = Math.round(_root.player._y-this._y);
distancefromthis = Math.round(Math.sqrt((xdist*xdist)+(ydist*ydist)));
if (distancefromthis<150>=50) {
EmyRadians = Math.atan2(_root.player._y-this._y, _root.player._x-this._x);
EmyDegrees = Math.round((EmyRadians*180/Math.PI));
_root.yChange = Math.round(_root.player._y-this._y);
_root.xChange = Math.round(_root.player._x-this._x);
this._rotation = EmyDegrees+270;
this.walkTo(_root.player._x, _root.player._y);
this.gotoAndStop(2);
}
if (distancefromthis<50>
EmyRadians = Math.atan2(_root.player._y-this._y, _root.player._x-this._x);
EmyDegrees = Math.round((EmyRadians*180/Math.PI));
_root.yChange = Math.round(_root.player._y-this._y);
_root.xChange = Math.round(_root.player._x-this._x);
this._rotation = EmyDegrees+270;
this.gotoAndStop(3);
}
if (distancefromthis>=150) {
this.gotoAndStop(1);
}
function walkTo(X, Y) {
// Y-Axis movement
if (this._y<(Y-20)) {
this._y += 2;
} else if (this._y>(Y+20)) {
this._y -= 2;
}
// X-Axis Movement
if (this._x<(X-40)) {
this._x += 2;
this._xscale = -100;
} else if (this._x>(X+40)) {
this._x -= 2;
this._xscale = 100;
} } } //end spider
//li
onClipEvent (load) {
var attack = 5;
if (this._name == "li" {
this._visible = false;
} else {
this._visible = true;
}
this._x = _root.player._x;
this._y = _root.player._y;
this._rotation = _root.player._rotation;
shotxspeed = 20*Math.sin(_root.player._rotation*(Math.PI/180));
shotyspeed = 20*Math.cos(_root.player._rotation*(Math.PI/180));
}
onClipEvent (enterFrame) {
_root.visible(this);
this._x += shotxspeed;
this._y -= shotyspeed;
if (_root.player._x-220>this._x || this._x>_root.player._x+200) {
unloadMovie(this);
} }
// end li
//cb
onClipEvent (load) {
var s = 0;
var r = 0;
}
onClipEvent (enterFrame) {
_root.visible(this);
_root.rollover(this, "Lighting bolt"
if (this.s != 0) {
_root.player.moving = false;
_root.player.gotoAndStop(1);
startDrag(this, true);
_root.cursor._visible = false;
}
if (r != 0) {
_root.player.selected = 1;
_root.ib4.e = 1;
} else {
_root.player.selected = 0;
_root.ib4.e = 0;
}
}
onClipEvent (mouseDown) {
if (_root.cursor.hitTest(this)) {
this.s = 1;
}
}
onClipEvent (mouseUp) {
if (this.hitTest(_root.ib1) && _root.ib4.e != 1) {
this._x = _root.ib1._x;
this._y = _root.ib1._y;
this.r++;
} else {
if (this.hitTest(_root.ib2) && _root.ib4.e != 1) {
this._x = _root.ib2._x;
this._y = _root.ib2._y;
this.r++;
} else {
if (this.hitTest(_root.ib3) && _root.ib4.e != 1) {
this._x = _root.ib3._x;
this._y = _root.ib3._y;
this.r++;
} else {
if (this.hitTest(_root.ib4) && _root.ib4.e != 1) {
this._x = _root.ib4._x;
this._y = _root.ib4._y;
this.r++;
} else {
this.r = 0;
}
}
} }
this.s = 0;
stopDrag();
_root.cursor._visible = true;
}
//end cb
//arm
onClipEvent (load) {
var s = 0;
var r = 0;
}
onClipEvent (enterFrame) {
_root.visible(this);
_root.rollover(this, "Armor"
if (this.s != 0) {
_root.player.moving = false;
_root.player.gotoAndStop(1);
startDrag(this, true);
_root.cursor._visible = false;
}
if (r != 0) {
duplicateMovieClip(_root.arm, "arm2", 2);
_root.arm2._x = _root.player._x;
_root.arm2._y = _root.player._y;
_root.arm2._rotation = _root.player._rotation;
_root.player.speed -= 1;
} else {
removeMovieClip(_root.arm2);
_root.player.speed = _root.player.oldspeed;
}
}
onClipEvent (mouseDown) {
if (_root.cursor.hitTest(this)) {
this.s = 1;
this.r = 0;
} }
onClipEvent (mouseUp) {
for (i=5; i<=8; i++) {
if (this.hitTest(_root["ib"+i])) {
this._x = _root["ib"+i]._x;
this._y = _root["ib"+i]._y+5;
this.r++;
}
}
this.s = 0;
_root.cursor._visible = true;
stopDrag();
}
//end arm
//hel onClipEvent (load) {
var s = 0;
var r = 0;
}
onClipEvent (enterFrame) {
_root.visible(this);
_root.rollover(this, "Helmet"
if (this.s != 0) {
_root.player.moving = false;
_root.player.gotoAndStop(1);
startDrag(this, true);
_root.cursor._visible = false;
}
if (r != 0) {
duplicateMovieClip(_root.hel, "hel2", 1);
_root.hel2._x = _root.player._x;
_root.hel2._y = _root.player._y;
_root.hel2._rotation = _root.player._rotation;
_root.player.speed -= 1;
} else {
removeMovieClip(_root.hel2);
_root.player.speed = _root.player.oldspeed;
} }
onClipEvent (mouseDown) {
if (_root.cursor.hitTest(this)) {
this.s = 1;
this.r = 0;
} }
onClipEvent (mouseUp) {
for (i=5; i<=8; i++) {
if (this.hitTest(_root["ib"+i])) {
this._x = _root["ib"+i]._x;
this._y = _root["ib"+i]._y+10;
this.r++;
} } this.s = 0;
_root.cursor._visible = true;
stopDrag();
} //end hell
//ib+{1,8}
onClipEvent (load) {
var se = 0;
}
onClipEvent (enterFrame) {
if (Key.isDown(49)) {
this.gotoAndStop(2);
} else {
this.gotoAndStop(1);
} }
- 2 Replies
if you Have to many loopings that's more likey to lag Hard.
I didn't want to read ALL THE CODING but Switch to Flash CS3.
its alot faster than mx.
You must be logged in to post a reply!