Code Snippets
Useful blocks of code
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
Info
I'll be posting little snippets of code in this thread that don't warrant an entire topic of their own. Mostly will be useful little methods of doing something that is easy enough in concept, but you might not know how to do in C# specifically.
Others can feel free to add their own to replies and I'll add them to this main post.
Methods
" Odd Or Even"
Author: garfunkle
Summary: Uses modulas to test if there is a remainder when deviding by 2. If there is no remainder then it means the number must be even.
Code:
/// <summary>
/// Will return true if there is no remainder,
/// i.e. the number can be devided by two and is
/// therefore even.
/// </summary>
/// <param name="num">The integer value to test</param>
/// <returns>True or False</returns>
public bool IsEven(int num)
{
if (num % 2 == 0)
return true;
return false;
}
"Temp Folder Location"
Author: Microsoft
Summary: Returns a string value representing the path to the systems temp folder.
Code:
string tempFolder = System.IO.Path.GetTempPath();
"Xna Scroll Wheel"
Summary: Returns the difference between scroll wheel now and in the previous frame.
Code:
/// <summary>
/// Returns how much the scroll wheel has changed
/// </summary>
public float ScrollWheelDiff
{
get { return (float)(mouseState.ScrollWheelValue - previousmouseState.ScrollWheelValue); }
}
http://www.creationasylum.net/forum/index....mp;#entry333464