Table of Contents


Sparrow contains several handy preprocessor macros that can make your life easier.


Sparrow expects all angles in radians (different to Flash, which uses degrees in some places and radians in others). To convert between degrees and radians, you can use the following simple macros.

float degrees = SP_R2D(PI);  // -> 180.0f
float radians = SP_D2R(180); // -> PI


In Sparrow, colors are specified in hexadecimal format. Here are a few samples:

// format:   0xRRGGBB
uint red   = 0xff0000;
uint green = 0x00ff00; // or 0xff00
uint blue  = 0x0000ff; // or 0xff
uint white = 0xffffff;
uint black = 0x000000; // or simply 0

If you're not comfortable with the hexadecimal format, there are macros that help you with that. The macro SP_COLOR expects the red, green and blue components in a range between 0 and 255.

uint yellow = SP_COLOR(255, 255, 0); // -> 0xffff00

Sometimes, you've got a color and want to find out the red, green and blue components. You can do that, too.

uint yellow = 0xffff00;
uint redPartOfYellow   = SP_COLOR_PART_RED(yellow);   // -> 255
uint greenPartOfYellow = SP_COLOR_PART_GREEN(yellow); // -> 255
uint bluePartOfYellow  = SP_COLOR_PART_BLUE(yellow);  // -> 0

Comparing floats

Be careful when you compare 2 float or double values. Due to the nature of this datatype, it might lead to unexpected results. Sparrow has a simple macro that compares if two floating point values are reasonably equal.

Beware, though, that this macro is best suited for small ranges (say, smaller than 1 million). For larger values, the used delta value may be too small.

float f = 0.00001f;
bool isNearlyZero = SP_IS_FLOAT_EQUAL(f, 0.0f); // -> true

Next section: Event Handling

  manual/macros.txt · Last modified: 2013/05/27 10:58 by daniel
Powered by DokuWiki