1
Graphics / Scrolling of Tilemaps
« on: February 15, 2009, 08:06:54 pm »
Thanks a lot, that works much better ;-)
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Game Loop:
// Clear screen
App.Clear();
if (Input.IsKeyDown(sf::Key::Up)) OffsetY = -48;
if (Input.IsKeyDown(sf::Key::Left)) OffsetX = -48;
if (Input.IsKeyDown(sf::Key::Down)) OffsetY += 48;
if (Input.IsKeyDown(sf::Key::Right)) OffsetX += 48;
View.Move(OffsetX, OffsetY); // Move the player
App.SetView(View); // Draw relative to the world
// maxHeight /maxWidht are the maximum tiles that are visible
for (int i=0;i<maxHeight;i++)
{
for (int j=0;j<maxWidth;j++)
{
CTile* tmpTile = new CTile(tileNames[map[i][j]]);
tmpTile->getTile().SetPosition ( j*48, i *48);
sf::Sprite sp = tmpTile->getTile();
App.Draw ( sp );
}
}
App.SetView(App.GetDefaultView()); // Draw relative to the GUI
App.Draw(Sprite); // Draw the player