I have cut down this code to a bare minimum, trying to draw a map for just one screen. Despite the map being only 25*18, I still experience this weird redraw effect. In addition, I tested the executable on 4 different Windows 7 machines (modern systems with decent power), the result remains the same. My map doesn't scroll smooth.
#include "Map.h"
#include "Main.h"
#include <iostream>
#include <string>
#include <sstream>
using namespace AGK;
app App;
int width = 0;
int height = 0;
int orientation = 0;
char* platform = NULL;
float mapx;
float mapy;
float ft=0;
int tileSheet;
void drawMap(float xp, float yp);
void app::Begin ( void )
{
agk::SetOrientationAllowed(0,0,1,1);
agk::SetVirtualResolution ( 800, 600);
int result = agk::SetCurrentDir("tiles");
tileSheet=agk::CreateSprite(agk::LoadImage("tiles.png"));
assert( result = 1);
agk::SetSyncRate(60,0);
drawMap(0,0);
}
void app::Loop(void)
{
ft = agk::GetFrameTime();
if(agk::GetRawKeyState(37)>=1) agk::SetViewOffset(mapx-=120*ft,mapy);
if(agk::GetRawKeyState(39)>=1) agk::SetViewOffset(mapx+=120*ft,mapy);
if(agk::GetRawKeyState(38)>=1) agk::SetViewOffset(mapx,mapy-=120*ft);
if(agk::GetRawKeyState(40)>=1) agk::SetViewOffset(mapx,mapy+=120*ft);
agk::Sync();
}
void app::End(void)
{
}
void drawMap(float xp, float yp)
{
int map [25*18]={
71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,
71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71
};
int x, y;
int bx = 0;
int by = 0;
int count=0;
int clone;
for( y = 0; y < 18; y++ )
{
for( x = 0; x < 25; x++ )
{
if(map[x+y*25]!=0)
{
clone=agk::CloneSprite(tileSheet);
agk::SetSpriteFrame(tileSheet,map[x+y*25]);
agk::SetSpritePosition ( tileSheet, bx+xp, by+yp );
}
bx += 32;
count++;
}
bx = 0;
by += 32;
}
}
Any suggestions are as always appreciated.