Kren, I think I will post the optimization here as well. So that we all can learn it.
OK, here's my optimization...
Edit:
1. Mario -> KeyDown -> Space to be:
- Code: Select all
int tmp=antigravity;
if(tmp==-1)
{
ChangeAnimation("Event Actor", "upside down right", FORWARD);
antigravity=1;
}
if(tmp==1)
{
ChangeAnimation("Event Actor", "Small_Mario_Run_Right", FORWARD);
antigravity=-1;
}
2. Mario -> DrawActor to be:
- Code: Select all
x+=8;
yvelocity=-antigravity*12;
it will make yvelocity to be 12 if antigravity is -1, and -12 if antigravity is 1.
So the basic is just use the antigravity value to decide the yvelocity.
Even simpler than using IF ELSE right?
Also, don't forget to add:
Mario -> CreateActor:
- Code: Select all
antigravity=1;
As the default value. Since we don't use 0 value anymore, so we need to set the initial value.
If you want to make it even simpler, you can edit the Keydown code to be like this:
- Code: Select all
int tmp=antigravity;
char str[4][64]={"Small_Mario_Run_Right","none","upside down right"};
ChangeAnimation("EventActor", str[tmp+1], FORWARD);
antigravity=tmp*-1;
So it will change the animation by pointing the array value.
If tmp is -1, then it will point str[0], where str[0] is "Small_Mario_Run_Right"
If tmp is 1, then it will point str[2], where str[2] is "upside down right"
What about str[1] then???
It will point str[1] if tmp is 0. Since we don't use 0 value for tmp (or antigravity in this case), so we can just ignore it.
That's why I type "none" on it.
Hope that helps