Quote: "So basically its like point sprite but with a step value?"
Yes, kind of like a Lerp
Quote: "Will a negative value make it rotate opposite direction or does it just take the shortest way?"
Yes shortest way round and No, for that we need the RotateSprite(sprite_id, amount) but I figured SetSpriteAngle(sprite_id, GetSpriteAngle(sprite_id)+amount) is not to painful to type out anyway so not much point in adding it?
Its to easy to go overboard and add in loads of unneeded functions, 102 flavours of CreateSprite and 19 angle functions are just not needed, I thought those 4 functions would save some headaches for the noobs and my make my own life a little easier.
Make the sprite follow the mouse:
float mouse_x = agk::GetRawMouseX();
float mouse_y = agk::GetRawMouseY();
if (agk::GetRawMouseLeftState())
{
agk::MoveSpriteLocalX(parent_1_id, 1.5f);
agk::TurnSpriteToPosition(parent_1_id, mouse_x, mouse_y, 0.5f);
}
And the full C++ test code for the 4 functions, it creates 2 parent sprites and attaches a bunch of child sprites to each parent with FixSpriteToSprite, one will follow the mouse on the x axis on left button, the other will follow the mouse on the y axis on the right button, 1 parent is setup to use sprite offset the other is not, this was for testing the internal code.
// Includes
#include "template.h"
// Namespace
using namespace AGK;
app App;
UINT parent_1_id;
UINT parent_2_id;
const int USE_OFFSET = 1;
UINT CreateChildSprite(UINT parent, float x, float y, int r, int g, int b)
{
UINT child_id = agk::CreateSprite(0);
agk::SetSpriteSize(child_id, 20, 10);
agk::SetSpritePosition(child_id, x, y);
agk::SetSpriteColor(child_id, r, g, b, 255);
agk::FixSpriteToSprite(child_id, parent);
return child_id;
}
UINT CreateChildSpriteByOffset(UINT parent, float x, float y, int r, int g, int b)
{
UINT child_id = agk::CreateSprite(0);
agk::SetSpriteSize(child_id, 20, 20);
agk::SetSpriteOffset(child_id, 10, 10);
agk::SetSpritePositionByOffset(child_id, x, y);
agk::SetSpriteColor(child_id, r, g, b, 255);
agk::FixSpriteToSprite(child_id, parent);
return child_id;
}
void app::Begin(void)
{
agk::SetVirtualResolution(1024, 768);
agk::SetClearColor(151, 170, 204); // light blue
agk::SetSyncRate(60, 0);
agk::SetScissor(0, 0, 0, 0);
// Test with sprite offset (Left Bitton)
parent_1_id = agk::CreateSprite(0);
agk::SetSpriteSize(parent_1_id, 100, 30);
agk::SetSpriteColor(parent_1_id, 255, 0, 0, 255);
agk::SetSpriteOffset(parent_1_id, 50, 15);
agk::SetSpritePositionByOffset(parent_1_id, 0, 0);
CreateChildSpriteByOffset(parent_1_id, 60, 0, 0, 0, 255);
CreateChildSpriteByOffset(parent_1_id, 40, -15, 0, 255, 0);
CreateChildSpriteByOffset(parent_1_id, 40, 15, 0, 255, 0);
CreateChildSpriteByOffset(parent_1_id, -40, -15, 255, 255, 0);
CreateChildSpriteByOffset(parent_1_id, -40, 15, 255, 255, 0);
agk::SetSpritePositionByOffset(parent_1_id, 200, 200);
// Test with no offset (Right Button)
parent_2_id = agk::CreateSprite(0);
agk::SetSpriteSize(parent_2_id, 100, 30);
agk::SetSpriteColor(parent_2_id, 255, 0, 0, 255);
agk::SetSpritePosition(parent_2_id, 0, 0);
CreateChildSprite(parent_2_id, 110, 5, 0, 0, 255);
CreateChildSprite(parent_2_id, 80, -15, 0, 255, 0);
CreateChildSprite(parent_2_id, 80, 35, 0, 255, 0);
CreateChildSprite(parent_2_id, 20, -15, 255, 255, 0);
CreateChildSprite(parent_2_id, 20, 35, 255, 255, 0);
agk::SetSpritePosition(parent_2_id, 400, 400);
}
int app::Loop(void)
{
float mouse_x = agk::GetRawMouseX();
float mouse_y = agk::GetRawMouseY();
if (agk::GetRawMouseLeftState())
{
agk::MoveSpriteLocalX(parent_1_id, 1.5f);
agk::TurnSpriteToPosition(parent_1_id, mouse_x, mouse_y, 0.5f);
}
if (agk::GetRawMouseRightState())
{
agk::MoveSpriteLocalY(parent_2_id, 1.5f);
agk::TurnSpriteToPosition(parent_2_id, mouse_x, mouse_y, 0.5f);
}
agk::Print(agk::ScreenFPS());
agk::Sync();
return 0; // return 1 to close app
}
void app::End(void)
{
}