Fangames > Programming Questions
Invincibility Frames
infern0man1:
In the future, use the edit button instead of the post feature; it's against the rules to triple post unless each post is spread far enough away from each other in time or the content in it is too large to fit into one post (which really shouldn't happen either).
LoneTree_tv:
--- Quote from: infern0man1 on July 27, 2015, 01:54:10 AM ---In the future, use the edit button instead of the post feature; it's against the rules to triple post unless each post is spread far enough away from each other in time or the content in it is too large to fit into one post (which really shouldn't happen either).
--- End quote ---
Sorry. :atkCry:
I didn't want to post so many times,
but I forgot that editing existed.
Derf:
I'm not sure it makes much of a difference to the speed of the code but it's probably better to use the in-built function for visibility than image_alpha since you're just using 0 & 1 anyway. e.g. "visible = 1" or "visible = 0".
Also when you're just using boolean data (a value that is either 1 or 0/true or false) you can just do the following:
--- Code: ---visible = !visible;
--- End code ---
instead of
--- Code: ---if (visible = 0) {
visible = 1;
}
else if (visible = 1) {
visible = 0;
}
--- End code ---
Again, it's not a big enough thing to cause slowdown in the game but it is quicker for GM to process and is a good habit simply because it requires you to type less.
HAEGOE:
Well, I'm using this code to toggle a couple of frames later
--- Code: ---if IFrame>0 and IFrame mod 4 <2{
//the former is to make sure invisibility toggling works only when invincible, and the latter is for setting toggle interval
visible = 0;
}else{//when the boss is not invincible or when toggled from invisible to visible
visible = 1;
}
--- End code ---
in the code above, I setted the interval to 2, means boss' invisibility changes each 2 frames.
If you want to increase it(decreasing would means setting it to 1, in which case It's better to use what derf said), you can write it this way
--- Code: ---if IFrame>0 and IFrame mod (interval X2) <(interval){
//same as above. I suggest writing value as natural number
visible = 0;
}else{
visible = 1;
}
--- End code ---
LoneTree_tv:
Wow. Thanks so much!
But one more thing, can you break down the first lines of code for both of the segments?
I don't understand "mod 4 <2" and "mod (interval X2) <(interval)" very well.
Just for future usage, I'd like to know what they do.
Thanks in advance :atkHappy:
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version