Ok, I'm trying to use the MapRenderer class provided here (
http://pastebin.com/SrBE69EC), and it works fine with the built in example, that draws only colored tiles with no texture, wrapping around. The moment I try to get a spritesheet into the mix, it stops working, and I get a black screen with nothing. Here's the relevant code:
#include <SFML/Graphics.hpp>
#include <TGUI/TGUI.hpp>
#include "World.h"
#include "MapRenderer.h"
using namespace sf;
#define screenWidth 1024
#define screenHeight 768
#define PI 3.14
#define fps 30
#define tileSize 32
void provider(int x, int y, int layer, Color& color, IntRect &src)
{
//color = Color::Yellow;
src = IntRect(10, 42, 32, 32);
}
void main()
{
sf::Clock clock; // starts the clock
sf::Time elapsed = elapsed.Zero;
sf::RenderWindow window(sf::VideoMode(screenWidth, screenHeight), "SFML works!");
View view = window.getDefaultView();
Texture texture;
texture.loadFromFile("World_A2.png");
MapRenderer map(&texture, provider, 32, 1);
Vector2f prev;
tgui::Gui gui(window);
gui.setGlobalFont("TGUI/fonts/DejaVuSans.ttf");
World *world=new World;
world->generate(1000,1000);
int screenX=500, screenY=500;
//Main Loop
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
Vector2f ms, delta;
switch (event.type)
{
case Event::Closed:
window.close();
break;
case Event::Resized:
view.setSize(event.size.width, event.size.height);
view.setCenter(view.getSize() * 0.5f);
break;
case Event::MouseMoved:
ms = Vector2f(event.mouseMove.x, event.mouseMove.y);
delta = ms - prev;
if (Mouse::isButtonPressed(Mouse::Button::Left))
view.setCenter(view.getCenter() - delta);
prev = ms;
break;
case Event::KeyPressed:
map.refresh();
break;
}
gui.handleEvent(event);
}
elapsed += clock.restart();
if (elapsed.asMilliseconds() > 1000 / fps) // is it time to loop again?
{
elapsed -= sf::milliseconds(1000 / fps);
window.clear();
window.setView(view);
map.update(window);
window.draw(map);
// Sprite test;
// test.setTexture(texture);
// window.draw(test); <-This was to test if the texture was actually loading correctly, it does
// draw the spritesheet on screen when uncommented
//GUI
gui.draw();
window.display();
}
else sf::sleep(sf::milliseconds(10));
}
}
Any help?