Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - lethoz

Pages: [1]
1
Graphics / Scrolling of Tilemaps
« on: February 15, 2009, 08:06:54 pm »
Thanks a lot, that works much better ;-)

2
Graphics / Scrolling of Tilemaps
« on: February 15, 2009, 04:58:47 pm »
Hi,

i did very much research in this forum how to implement scrolling tilemaps with SFML.

I read the post from Petri Irri how to archive scrolling of tile maps(http://www.sfml-dev.org/forum/viewtopic.php?t=773&highlight=scroll+tilemap). But i cannot get mine to work .

Here's what i got:
1) I got code to load and manage tiles.
2) I can draw a tilemap that fills out the screen. (every tile is 48x48)
3) I can move the player sprite around the screen.

But that code doesn't work too well:
Code: [Select]

       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


Did i miss something ?
Should the visible rect of the tilemap be rendered to an image and then being drawn ?

Any help is appreciated !

Thanks in advance,
Chris

Pages: [1]