From ebb3d3c754a50fccdc8f780d3297361925f33a85 Mon Sep 17 00:00:00 2001 From: totycro Date: Wed, 6 Apr 2011 16:08:19 +0200 Subject: Keep track of PixmapItems in client --- pacman-c++/mainwidget.cpp | 13 ++++++++++++- pacman-c++/mainwidget.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index bf049f2..a3acc45 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp @@ -56,6 +56,11 @@ Transmission::map_t createDummyMap() MainWidget::MainWidget() : currentKey(0) { + visualMap.resize(Constants::map_size.width); + for (int i=0; i(cur & Transmission::color_mask); qDebug() << "col=" << color; - PixmapItem *item = NULL; + PixmapItem* item = NULL; if (cur & Transmission::block) { unsigned int neighbours = Block::None; @@ -194,6 +199,12 @@ void MainWidget::updateMap(const Transmission::map_t& map) { m_scene->addItem(item); item->setPos(mapPositionToCoord(x, y)); + PixmapItem* oldItem = visualMap[x][y]; + visualMap[x][y] = item; + if (oldItem != NULL) { + m_scene->removeItem(item); + delete oldItem; + } } } } diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index 36e5624..951b6c6 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h @@ -29,7 +29,7 @@ private: void updateScore(); - PixmapItem ** visualMap; + QVector< QVector< PixmapItem* > > visualMap; // data conversion QPoint mapPositionToCoord(unsigned int x, unsigned int y); -- cgit v1.2.3