Skip to main content
Version: 1.0.0-preview.37

Velaptor.GameHelpers

Velaptor

Velaptor

GameHelpers Class

Provides extension helper methods for common game related operations.

public static class GameHelpers

Inheritance System.Object → GameHelpers

Methods

ApplySize(this float, float)

Returns the given value with the given size applied.

public static float ApplySize(this float value, float size);

Parameters

value System.Single

The value to apply the size to.

size System.Single

The size to apply.

Returns

System.Single
The value after the size has been applied.

Example

If the value was 3 and the size was 2, then the result would be 6.

Remarks

A size value of 1 represents 100% or the unchanged normal size of the value.
If the value of size is 2, then the result would be the given
value that is doubled.

ApplySize(this RectangleF, float)

Returns the given value with the given size applied.

public static System.Drawing.RectangleF ApplySize(this System.Drawing.RectangleF value, float size);

Parameters

value System.Drawing.RectangleF

The System.Drawing.RectangleF to apply the size to.

size System.Single

The size to apply.

Returns

System.Drawing.RectangleF
The result after the size has been applied.

Remarks

The size will be applied to the following:

ApplySize(this SizeF, float)

Returns the given value with the given size applied.

public static System.Drawing.SizeF ApplySize(this System.Drawing.SizeF value, float size);

Parameters

value System.Drawing.SizeF

The System.Drawing.SizeF to apply the size to.

size System.Single

The size to apply.

Returns

System.Drawing.SizeF
The result after the size has been applied.

Remarks

The size will be applied to the following:

ApplySize(this uint, float)

Returns the given value with the given size applied.

public static float ApplySize(this uint value, float size);

Parameters

value System.UInt32

The value to apply the size to.

size System.Single

The size to apply.

Returns

System.Single
The value after the size has been applied.

Example

If the value was 3 and the size was 2, then the result would be 6.

Remarks

A size value of 1 represents 100% or the unchanged normal size of the value.
If the value of size is 2, then the result would be the given
value that is doubled.

ApplySize(this GlyphMetrics, float)

Returns the given value with the given size applied.

public static Velaptor.Graphics.GlyphMetrics ApplySize(this Velaptor.Graphics.GlyphMetrics value, float size);

Parameters

value GlyphMetrics

The GlyphMetrics to apply the size to.

size System.Single

The size to apply.

Returns

GlyphMetrics
The result after the size has been applied.

Remarks

The size will be applied to the following:

The size will NOT be applied to the following:

DecreaseBrightness(this Color, float)

Decreases the brightness of the color using the given brightness value.

public static System.Drawing.Color DecreaseBrightness(this System.Drawing.Color clr, float brightness);

Parameters

clr System.Drawing.Color

The color to change.

brightness System.Single

The amount of brightness to apply.

Returns

System.Drawing.Color
The new color with the brightness applied.

Example

var clr = Color.FromArgb(255, 10, 20, 30);  


// Increase the brightness by 20%
clr = clr.IncreaseBrightness(0.2f);

In the example above, the values would equal the results below:

  • Alpha value would be unchanged with a value of 255.
  • Red component with brightness applied would result in a value of 8.
  • Green component with brightness applied would result in a value of 16.
  • Blue component with brightness applied would result in a value of 24.

Remarks

The brightness value must be a value between 0.0 and 1.0.

If a value lower than 0.0 or greater than 1.0, the brightness will automatically
be adjusted within the range of 0.0 to 1.0.

Think of the brightness value as a percentage between 0% and 100%.

The System.Drawing.Color.System.Drawing.Color.A color component is not effected.

DoesNotContain(this string, char)

Returns a value indicating whether a specified character occurs within this string.

public static bool DoesNotContain(this string stringToSearchIn, char value);

Parameters

stringToSearchIn System.String

The string to search that may or may not contain the value.

value System.Char

The character to seek.

Returns

System.Boolean
true if the value parameter does not occur within this string.

DoesNotContain(this string, string)

Returns a value indicating whether a specified substring occurs within this string.

public static bool DoesNotContain(this string stringToSearchIn, string value);

Parameters

stringToSearchIn System.String

The string to search that may or may not contain the value.

value System.String

The string to seek.

Returns

System.Boolean
true if the value parameter does not occur within this string.

DoesNotOnlyContainsLetters(this string)

Returns a value indicating whether this string does not only contain letters.

public static bool DoesNotOnlyContainsLetters(this string value);

Parameters

value System.String

The string to check.

Returns

System.Boolean
true if the string contains other characters besides letters.

ForceNegative(this float)

Sets the value to negative if it's positive.

public static float ForceNegative(this float value);

Parameters

value System.Single

The value to force.

Returns

System.Single
The value as a negative number.

ForcePositive(this float)

Sets the value to positive if it's negative.

public static float ForcePositive(this float value);

Parameters

value System.Single

The value to force.

Returns

System.Single
The value as a positive number.

GetPosition(this RectangleF)

Returns the position in the given rect as a System.Numerics.Vector2.

public static System.Numerics.Vector2 GetPosition(this System.Drawing.RectangleF rect);

Parameters

rect System.Drawing.RectangleF

The rect that contains the position.

Returns

System.Numerics.Vector2
The System.Drawing.RectangleF position as a System.Numerics.Vector2.

IncreaseBrightness(this Color, float)

Increases the brightness of the color using the given brightness value.

public static System.Drawing.Color IncreaseBrightness(this System.Drawing.Color clr, float brightness);

Parameters

clr System.Drawing.Color

The color to change.

brightness System.Single

The amount of brightness to apply.

Returns

System.Drawing.Color
The new color with the brightness applied.

Example

var clr = Color.FromArgb(255, 10, 20, 30);  


// Increase the brightness by 20%
clr = clr.IncreaseBrightness(0.2f);

In the example above, the values would equal the results below:

  • Alpha component would be unchanged with a value of 255.
  • Red component with brightness applied would result in a value of 12.
  • Green component with brightness applied would result in a value of 24.
  • Blue component with brightness applied would result in a value of 36.

Remarks

The brightness value must be a value between 0.0 and 1.0.

If a value lower than 0.0 or greater than 1.0, the brightness will automatically
be adjusted within the range of 0.0 to 1.0.

Think of the brightness value as a percentage between 0% and 100%.

The System.Drawing.Color.System.Drawing.Color.A color component is not effected.

IsLetter(this char)

Returns a value indicating whether the character is a letter.

public static bool IsLetter(this char character);

Parameters

character System.Char

The character to check.

Returns

System.Boolean
True if the character is an upper or lower case letter.

IsNotLetter(this char)

Returns a value indicating whether the character is not a letter.

public static bool IsNotLetter(this char character);

Parameters

character System.Char

The character to check.

Returns

System.Boolean
True if the character is not an upper or lower case letter.

MapValue(this byte, byte, byte, byte, byte)

Maps the given value from one range to another.

public static byte MapValue(this byte value, byte fromStart, byte fromStop, byte toStart, byte toStop);

Parameters

value System.Byte

The value to map.

fromStart System.Byte

The starting value of the start range.

fromStop System.Byte

The ending value of the start range.

toStart System.Byte

The starting value of the end range.

toStop System.Byte

The ending value of the end range.

Returns

System.Byte
A value that has been mapped to a range between toStart and toStop.

Remarks

Be careful when restricting the 'to' values to a value between 0 and 1. This will always return a value
of 0. This is because the return type is a byte and any value between the values of 0 and 1 is
a floating point value and floating point values cannot be represented with a byte data type.

This results in a value of 0 with a loss of information. If you need to return a value that
is between the values of 0 and 1, use the method overload MapValue(this int, float, float, float, float).

MapValue(this byte, float, float, float, float)

Maps the given value from one range to another.

public static float MapValue(this byte value, float fromStart, float fromStop, float toStart, float toStop);

Parameters

value System.Byte

The value to map.

fromStart System.Single

The starting value of the start range.

fromStop System.Single

The ending value of the start range.

toStart System.Single

The starting value of the end range.

toStop System.Single

The ending value of the end range.

Returns

System.Single
A value that has been mapped to a range between toStart and toStop.

MapValue(this float, float, float, float, float)

Maps the given value from one range to another.

public static float MapValue(this float value, float fromStart, float fromStop, float toStart, float toStop);

Parameters

value System.Single

The value to map.

fromStart System.Single

The starting value of the start range.

fromStop System.Single

The ending value of the start range.

toStart System.Single

The starting value of the end range.

toStop System.Single

The ending value of the end range.

Returns

System.Single
A value that has been mapped to a range between toStart and toStop.

MapValue(this int, float, float, float, float)

Maps the given value from one range to another.

public static float MapValue(this int value, float fromStart, float fromStop, float toStart, float toStop);

Parameters

value System.Int32

The value to map.

fromStart System.Single

The starting value of the start range.

fromStop System.Single

The ending value of the start range.

toStart System.Single

The starting value of the end range.

toStop System.Single

The ending value of the end range.

Returns

System.Single
A value that has been mapped to a range between toStart and toStop.

OnlyContainsLetters(this string)

Returns a value indicating whether this string only contains letters.

public static bool OnlyContainsLetters(this string value);

Parameters

value System.String

The string to check.

Returns

System.Boolean
true if the string only contains letters.

RotateAround(this Vector2, Vector2, float, bool)

Rotates the vector around the origin at the given angle.

public static System.Numerics.Vector2 RotateAround(this System.Numerics.Vector2 vector, System.Numerics.Vector2 origin, float angle, bool clockWise=true);

Parameters

vector System.Numerics.Vector2

The vector to rotate.

origin System.Numerics.Vector2

The origin to rotate the vector around.

angle System.Single

The angle in degrees to rotate vector. Value must be positive.

clockWise System.Boolean

Determines the direction the given vector should rotate around the origin.

Returns

System.Numerics.Vector2
The vector rotated around the origin.

ToDegrees(this float)

Converts the given radians value into degrees.

public static float ToDegrees(this float radians);

Parameters

radians System.Single

The value to convert.

Returns

System.Single
The radians converted into degrees.

ToRadians(this float)

Converts the given degrees value into radians.

public static float ToRadians(this float degrees);

Parameters

degrees System.Single

The value to convert.

Returns

System.Single
The degrees converted into radians.

ToVector4(this Color)

Converts the given System.Drawing.Color to a System.Numerics.Vector4
with each component holding the color component values.

public static System.Numerics.Vector4 ToVector4(this System.Drawing.Color clr);

Parameters

clr System.Drawing.Color

The color to convert.

Returns

System.Numerics.Vector4
A 4 component vector of color values.
X = red.
Y = green.
Z = blue.
W = alpha.