Skip to content

3.cSprite Function List

Aaron Liddiment edited this page Nov 16, 2015 · 13 revisions

###cSprite(uint16_t Width = 0, uint16_t Height = 0, const uint8_t *Data = NULL, uint8_t NumFrames = 0, SpriteNumBits_t BitsPixel = _1BIT, const struct CRGB *ColTable = NULL, const uint8_t *Mask = NULL);

###void Setup(uint16_t Width, uint16_t Height, const uint8_t *Data, uint8_t NumFrames, SpriteNumBits_t BitsPixel, const struct CRGB *ColTable, const uint8_t *Mask = NULL);

There are two ways to setup a Sprite, the first way is to do this when the variable is declared and the second is to call the Setup() function in your code. The parameters are the same for both methods.
Width & Height are the size of the sprite data in pixels/leds.
Data is a pointer to the bit packed sprite image data.
NumFrames is how many full sprite images are sequentially declared in the above data.
BitsPixel can be _1BIT, _2BIT, _3BIT, _4BIT, _5BIT & _8BIT. This the number of bits used in the image data per pixel/led.
ColTable is a pointer to an array of 1, 3, 7, 15, 31 or 255 CRGB's. The number of colours in the array is related to the BitsPixel above.
Mask is a pointer to single bit data that can be used for collision detection.

###void SetPosition(int16_t X, int16_t Y);
Sets the X & Y position of the sprite on the led matrix.

###void SetFrame(uint8_t Frame, uint8_t FrameRate = 0);
Sets the Image Frame number and optionally the rate of change, if the FrameRate is '0' then it will not automatically change frames.

###void SetMotion(int8_t XChange, uint8_t XRate, int8_t YChange, uint8_t YRate);
Sets the X & Y change values and the rate of change. If the XRate and/or YRate is '0' then the appropriate axis motion will be disabled.

###void SetOptions(uint8_t Options);
To use any of these options your must supply the Mask Data when setting up the Sprite.
Can be one or more of the following defines:-
SPRITE_X_KEEPIN
SPRITE_Y_KEEPIN
If the sprite collides with the selected matrix edge when using auto motion, its selected direction will be reversed.
SPRITE_DETECT_EDGE
Allows detection of the sprite colliding with the edge of the matrix.
SPRITE_DETECT_COLLISION
Allows the detection of sprite to sprite collisions. These will only be detected between sprites that have this option set.

###void SetPositionFrameMotionOptions(int16_t X, int16_t Y, uint8_t Frame, uint8_t FrameRate, int8_t XChange, uint8_t XRate, int8_t YChange, uint8_t YRate, uint8_t Options = 0);
This is an alternative way to setup sprite control in one call rather than using the four separate functions listed above.

###uint8_t GetFlags();
These flags will only be valid when the Sprite has valid Mask Data.
Will return one or more of the following flags:-
SPRITE_EDGE_X_MIN
SPRITE_EDGE_X_MAX
SPRITE_EDGE_Y_MIN
SPRITE_EDGE_Y_MAX
Indicates that the sprite is in contact with the respective edge.
SPRITE_MATRIX_X_OFF
SPRITE_MATRIX_Y_OFF
Indicates that the sprite is completely off the matrix's respective axis.
SPRITE_COLLISION
Indicates that the sprite is in contact with one or more sprites. At the moment the only way to find out which one is to scan other sprite flags and then to do X/Y checks.

###uint8_t GetCurrentFrame();
Returns the sprites current image frame number.

###int8_t GetXChange();
###void SetXChange(int8_t XC);
Gets or sets the X axis change value when using auto motion.

###int8_t GetYChange();
###void SetYChange(int8_t YC);
Gets or sets the Y axis change value when using auto motion.

###void IncreaseFrame();
###void DecreaseFrame();
Manually changes the sprite image frame number.

###uint8_t GetXCounter();
###void SetXCounter(uint8_t Xcnt);
Gets or sets the internal X axis change rate countdown value when using auto motion.

###uint8_t GetYCounter();
###void SetYCounter(uint8_t Ycnt);
Gets or sets the internal Y axis change rate countdown value when using auto motion.

##The following functions are called internally by cLEDSprites and will generally not be called in your code.
###void Update();
Updates the sprite using motion & frame rates if set.
###void Render(cLEDMatrixBase *Matrix);
Draws the sprite on the matrix.
###void EdgeDetect(cLEDMatrixBase *Matrix);
Checks for edge detection of the sprite if required.

###boolean Combine(int16_t dx, int16_t dy, cSprite *Src);
This function was purely added to make my Tetris example easy to program ;) Adds the Src sprite data to the current sprite at the dx,dy position. The colour palettes must match.

Clone this wiki locally