Thanks for your indepth answer :) (though the intention of the thread was to learn how to do what i talked about^^ :D).
So im trying to implement the minimap now which is supposed to show the whole "map".
For this i simply made a dummy tilemap which size is greater than the renderwindows one.
I use the following views to render both the gameview and the minimap:
sf::View mapview(app_window.getDefaultView());
sf::View minimap(app_window.getDefaultView());
mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));
// some more code to generate tilemap and draw it with respective views
i get the following:
(http://up.picr.de/18510984rw.jpg)
Now for a real minimap i want it to show ALL tiles the map consists of (size is 20x20 with 32x32 pixels per tile), but zooming or resizing will somehow stretch the way its drawn in an undesired way (well i get that if you zoom it has to be contracted).
How would i set up a view for the minimap so that it will show all 20x20 tiles inside its viewport?
hi,
sadly that is not entirely true.
when i do this i get this:
(http://up.picr.de/18525384uy.jpg)
the view is shifted by some offset when i set the size of it to the size of the whole tilemap.
all i did was to add one line, which does what you told me:
sf::View mapview(app_window.getDefaultView());
sf::View minimap(app_window.getDefaultView());
//sf::View menu(app_window.getDefaultView());
mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));
minimap.setSize(20*32,20*32);
but i don't want this behaviour, i want the minimap to be drawn at the position specified in "setViewport" (well to be precise i want the map to be drawn at the top left corner of that viewport)
There's probably a simple bug in your code then. For instance, are you sure that your tilemap actually starts at 0,0?
If you could provide a complete and minimal example that has this problem then we might be able to help you find the bug.
Here is my complete code (note: was randomly changing some example stuff from sfGUI thats why the code is so ugly):
#include <SFML/Graphics.hpp>
#include <iostream>
sf::Texture m_tileset;
sf::VertexArray m_vertices;
void setTilemap()
{
m_tileset.loadFromFile("Tileset.png");
m_vertices.setPrimitiveType(sf::Quads);
m_vertices.resize(20*20*4); // we use some dummy numbers to get a mapwidth > renderwindow_width
for (unsigned int i = 0; i < 20; ++i)
{
for (unsigned int j = 0; j < 20; ++j)
{
//get the current tile number
int tileNumber = 34;
// find its position in the tileset texture
int tu = tileNumber % (m_tileset.getSize().x / 32);
int tv = tileNumber / (m_tileset.getSize().x / 32);
// get a pointer to the current tile's quad
sf::Vertex* quad = &m_vertices[(i + j * 20) * 4];
// define its 4 corners
quad[0].position = sf::Vector2f(i * 32, j * 32);
quad[1].position = sf::Vector2f((i + 1) * 32, j * 32);
quad[2].position = sf::Vector2f((i + 1) * 32, (j + 1) * 32);
quad[3].position = sf::Vector2f(i * 32, (j + 1) * 32);
// define its 4 texture coordinates
quad[0].texCoords = sf::Vector2f(tu * 32, tv * 32);
quad[1].texCoords = sf::Vector2f((tu + 1) * 32, tv * 32);
quad[2].texCoords = sf::Vector2f((tu + 1) * 32, (tv + 1) * 32);
quad[3].texCoords = sf::Vector2f(tu * 32, (tv + 1) * 32);
}
}
}
int main() {
// Create the main SFML window
float width = 320.f;
float height = 420.f;
sf::RenderWindow app_window( sf::VideoMode(width,height), "SFGUI Canvas Example", sf::Style::Titlebar | sf::Style::Close );
// Start the game loop
app_window.setFramerateLimit(20);
setTilemap();
sf::RenderStates states;
states = &m_tileset;
sf::View mapview(app_window.getDefaultView());
sf::View minimap(app_window.getDefaultView());
//sf::View menu(app_window.getDefaultView());
mapview.setViewport(sf::FloatRect(0.f,0.f,1.f,0.75f));
minimap.setViewport(sf::FloatRect(0.f, 0.75, 0.5, 0.25));
minimap.setSize(20*32,20*32);
while ( app_window.isOpen() ) {
sf::Event event;
while ( app_window.pollEvent( event ) ) {
// Close window : exit
if ( event.type == sf::Event::Closed ) {
app_window.close();
}
}
app_window.clear();
app_window.setView(mapview);
app_window.draw(m_vertices,states);
app_window.setView(minimap);
app_window.draw(m_vertices,states);
app_window.display();
}
return EXIT_SUCCESS;
}
the used tileset can be found in the attachment.
the map should start at (0,0), thats what you get for the quads position if i and j are both zero.