Looking for a Perofmrance Boost
Posted: Thu Jun 07, 2012 2:42 pm
Mostly, my game spikes sometimes between 30 and lower FPS (Game default is 30), and it spikes when Im in a room full of Goblins, so it has to be the code in my goblins thats lagging.
I have WAY TOO MANY if statements, but I have no idea what do change in it to make it work otherwise.
I would like it if someone can increase the performance of this code for me. Thanks! +1 to whoever does it.
safeDraw() is this code and its used for every actor outside of the view
I have WAY TOO MANY if statements, but I have no idea what do change in it to make it work otherwise.
I would like it if someone can increase the performance of this code for me. Thanks! +1 to whoever does it.
- Code: Select all
if(transp==0)
{
if(distance(x, y, Player.x, Player.y)<=220)
{
gTimer++;
if(gTimer==15)
{
CreateActor("rockchuck", "Rock", "(none)", "(none)", 0, 0, false);
gTimer=0;
}
if(Player.x>x)
{
x+=3;
ChangeAnimation("Event Actor", "gobRight", NO_CHANGE);
}
if(Player.x<x)
{
x-=3;
ChangeAnimation("Event Actor", "gobLeft", NO_CHANGE);
}
}
else {
switch(animindex)
{
case 0:
ChangeAnimation("Event Actor", "GivStandRight", NO_CHANGE);
break;
case 1:
ChangeAnimation("Event Actor", "GobStandLeft", NO_CHANGE);
break;
}
aTimer+=rand(3);
if(aTimer>=60)
{
aTimer=0;
switch(animindex)
{
case 3:
ChangeAnimation("Event Actor", "GivStandRight", NO_CHANGE);
break;
case 2:
ChangeAnimation("Event Actor", "GobStandLeft", NO_CHANGE);
break;
}
}
}
if((x<=(Player.x+3) && x>=(Player.x-3)) && gJump==0)
{
gJump=1;
yvelocity=-12;
}
if(yvelocity<5)
{
yvelocity++;
}
if(yvelocity>3)
{
gJump=1;
}
g+=25;
b+=25;
}
if(eHP<=-3&&cTimer==0)
{
cTimer=1;
transp=.9999;
yvelocity=0;
xvelocity=0;
PlaySound2("data/enemDefeated.wav", 1.000000, 1, 0.000000);
}
safeDraw();
safeDraw() is this code and its used for every actor outside of the view
- Code: Select all
void safeDraw()
{
if((xscreen>640||xscreen<0) || (yscreen>480||yscreen<0))
{
VisibilityState("Event Actor", DISABLE);
}
else {
VisibilityState("Event Actor", ENABLE);
}
}