hgeSprite::SetHotSpot
Set the rotation and positioning center point for a sprite.
Synopsis
void hgeSprite::SetHotSpot(float x, float y);
Parameters
- x — X coordinate of the hot spot relative to sprite's left edge
- y — Y coordinate of the hot spot relative to sprite's top edge
Description
The hot spot defines the sprite's anchor point for positioning and rotation. When you call Render(px, py), the hot spot is placed at (px, py). When you rotate the sprite, it rotates around the hot spot.
Default Value
By default, the hot spot is at (0, 0) — the top-left corner of the sprite.
Common Patterns
Center Hot Spot
For sprites that rotate around their center:
hgeSprite *spr = new hgeSprite(tex, 0, 0, 64, 64);
spr->SetHotSpot(32, 32); // Center of 64x64 sprite
Bottom-Center for Characters
For standing characters where (x, y) represents their feet position:
hgeSprite *character = new hgeSprite(tex, 0, 0, 32, 64);
character->SetHotSpot(16, 64); // Bottom center
Top-Left for UI
For UI elements where (x, y) is the top-left corner (default behavior):
hgeSprite *button = new hgeSprite(tex, 0, 0, 100, 30);
// Hot spot defaults to (0, 0), no change needed
Example
// Create a rotating enemy sprite
hgeSprite *enemy = new hgeSprite(texEnemy, 0, 0, 48, 48);
enemy->SetHotSpot(24, 24); // Center
float rotation = 0;
bool FrameFunc()
{
float dt = hge->Timer_GetDelta();
rotation += 2.0f * dt; // Rotate over time
return false;
}
bool RenderFunc()
{
hge->Gfx_BeginScene();
enemy->RenderEx(400, 300, rotation); // Rotates around center
hge->Gfx_EndScene();
return false;
}