I've a few Sprites moving across the screen and I found that *most* of the time movement would be smooth, then once in a while a 'glitch' would ruin the smoothness.
So I thought I'd use the Tweening function, but it still get the odd glitch in movement. Can anybody improve on my code to remove the odd movement glitch?
// includes
#include "template.h"
// namespace
using namespace AGK;
app App;
void app::Begin(void)
{
agk::SetWindowTitle("Move Ship");
agk::SetWindowSize(1024, 768, 1);
agk::SetDisplayAspect(1024 / 768);
agk::SetVirtualResolution(1024, 768);
agk::SetClearColor(150, 170, 204); // light blue
agk::SetSyncRate(60, 1);
agk::SetVSync(1);
agk::SetScissor(0,0,0,0);
// get bounds for full screen
float LeftEdge = agk::GetScreenBoundsLeft();
float RightEdge = agk::GetScreenBoundsRight();
float xPos = LeftEdge - 64.0;
// hide mouse pointer
agk::SetRawMouseVisible(0);
// create sprites
agk::LoadImage(1, "ship.png");
agk::SetSpriteOffset(1, 0, 0);
agk::CreateSprite(1, 1);
agk::CreateSprite(2, 1);
agk::CreateSprite(3, 1);
// position sprites
agk::SetSpritePosition(1, xPos, 152.0);
agk::SetSpritePosition(2, xPos, 352.0);
agk::SetSpritePosition(3, xPos, 552.0);
// define tween for sprites
agk::CreateTweenSprite(1, 15.0); // tweenID, duration in seconds
agk::SetTweenSpriteX(1, xPos, RightEdge, 0); // tweenID, startX, endX, interpolation method
// play sprite tweens
agk::PlayTweenSprite(1, 1, 0.0);
agk::PlayTweenSprite(1, 2, 0.0);
agk::PlayTweenSprite(1, 3, 0.0);
}
int app::Loop (void)
{
float FrameSpeed, FPS;
do
{
FrameSpeed = agk::GetFrameTime(); // internal framespeed (dampened to avoid jumps)
FPS = agk::ScreenFPS(); // actual FPS
agk::Print(FPS);
agk::UpdateAllTweens(FrameSpeed);
agk::Sync();
} while(agk::GetTweenSpritePlaying(1,1));
return 1;
}
void app::End(void)
{
}