Void OnUpdatevoid MyCanvas::OnUpdate()
{
while(RenderWindow::pollEvent(event)) {
if (event.type == sf::Event::MouseWheelMoved)
{
cout << "works!" << endl ;
}
}
TileMap map;
if (!map.load("d:/tileset.png", sf::Vector2u(3, 3), level, x * 4, y * 4))
{
system("pause");
}
// Clear screen
RenderWindow::clear(sf::Color::White);
// Rotate the sprite
RenderWindow::draw(map);
mySprite.rotate(myClock.getElapsedTime().asSeconds() * 100.f);
// Draw it
for (int j = 0; j <= x * 4; ++j)
{
sf::Vertex outlinex1[2] =
{
sf::Vertex(sf::Vector2f(j * 3, 0), sf::Color(154,154,154)),
sf::Vertex(sf::Vector2f(j * 3, y * 12), sf::Color(154, 154, 154))
};
RenderWindow::draw(outlinex1, 2, sf::Lines);
}
for (int j = 0; j <= y * 4; ++j)
{
sf::Vertex outliney1[2] =
{
sf::Vertex(sf::Vector2f(0, j * 3), sf::Color(154, 154, 154)),
sf::Vertex(sf::Vector2f(x * 12, j * 3), sf::Color(154, 154, 154))
};
RenderWindow::draw(outliney1, 2, sf::Lines);
}
for (int i = 0; i <= x; ++i)
{
sf::Vertex outlinex[2] =
{
sf::Vertex(sf::Vector2f(i * 12, 0), sf::Color::Black),
sf::Vertex(sf::Vector2f(i * 12, y * 12), sf::Color::Black)
};
RenderWindow::draw(outlinex, 2, sf::Lines);
}
for (int i = 0; i <= y; ++i)
{
sf::Vertex outliney[2] =
{
sf::Vertex(sf::Vector2f(0, i * 12), sf::Color::Black),
sf::Vertex(sf::Vector2f(x * 12, i * 12), sf::Color::Black)
};
RenderWindow::draw(outliney, 2, sf::Lines);
}
myClock.restart();
}
Function that called OnUpdateQSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) : QWidget(Parent),
myInitialized (false)
{
// Setup some states to allow direct rendering into the widget
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_NoSystemBackground);
// Set strong focus to enable keyboard events to be received
setFocusPolicy(Qt::StrongFocus);
// Setup the widget geometry
move(Position);
resize(Size);
// Setup the timer
myTimer.setInterval(FrameTime);
}
QSFMLCanvas::~QSFMLCanvas() {}
void QSFMLCanvas::showEvent(QShowEvent*)
{
if (!myInitialized)
{
// Under X11, we need to flush the commands sent to the server to ensure that
// SFML will get an updated view of the windows
#ifdef Q_WS_X11
//XFlush(QX11Info::display());
#endif
// Create the SFML window with the widget handle
//RenderWindow::create((void *) winId());
RenderWindow::create(reinterpret_cast<sf::WindowHandle>(winId()));
// Let the derived class do its specific stuff
OnInit();
// Setup the timer to trigger a refresh at specified framerate
connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
myTimer.start();
myInitialized = true;
}
}
QPaintEngine* QSFMLCanvas::paintEngine() const
{
return 0;
}
void QSFMLCanvas::paintEvent(QPaintEvent*)
{
// Let the derived class do its specific stuff
OnUpdate();
// Display on screen
RenderWindow::display();
}
void QSFMLCanvas::OnInit() {}
void QSFMLCanvas::OnUpdate() {}
Thanks