As far as I know that's the common way to iterate through vector containers / containers in general.
I read it in the book "C++ Primer" and "QT 4.6 - Gui Entwicklung mit C++" (a german book)
As far as I know that's the common way to iterate through vector containers / containers in general.
I read it in the book "C++ Primer" and "QT 4.6 - Gui Entwicklung mit C++" (a german book)
Sorry I was thinking about something else.
Your version is ok, but dangerous, since it will also allow i> maxVal.
With '<' you are on the safe side.
Did they really use != for this case, or did they use an iterator and compared it to <container>.end() (with !=)?I read it in the book "C++ Primer" and "QT 4.6 - Gui Entwicklung mit C++" (a german book)
Its not the same case!
But true, this is not the problem here.
Can you show your full paintEvent()? the problem must be somewhere there...
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
I'm not sure right now if they used != only for iteration with iterators in "C++ Primer", but I'm quite sure that they did it in "QT 4.6 - Gui Entwicklung" without iterators.
But anyway, here's the whole paintEvent:
Qt Code:
{ if(curTileset != NULL) { //1.Tileset gets drawn. for(int i = 0;i != curTileset->getTileContainer()->size();i++) painter.drawPixmap(*curTileset->getTileContainer()->at(i)->getPosition(),*curTileset->getTileContainer()->at(i)->getTileImage()); //2.Collision gets drawn (if collisionMode is true) if(this->mode == selectCollision) for(int i = 0;i != curTileset->getTileContainer()->size();i++) { //Attention!Multiline Code painter.drawPixmap*(curTileset->getTileContainer()->at(i)->getPosition(), *curTileset->getTileContainer()->at(i)->getCollisionType()->getPixmap()); } //3.TileID gets drawn (if true) if(this->tileIDsVisible) for(int i = 0;i != curTileset->getTileContainer()->size();i++) //Attention!Multiline Code painter.drawText(curTileset->getTileContainer()->at(i)->getPosition()->x() + 12, curTileset->getTileContainer()->at(i)->getPosition()->y() + 12, //4.Grid gets drawn (if true) if(this->gridVisible) { for(int i = 0;i <= curTileset->getImage()->height();i += 32) painter.drawLine(0,i,curTileset->getImage()->width(),i); for(int j = 0;j <= curTileset->getImage()->width();j += 32) painter.drawLine(j,0,j,curTileset->getImage()->height()); } } }To copy to clipboard, switch view to plain text mode
Thanks btw for your help so far.
Bad!I'm not sure right now if they used != only for iteration with iterators in "C++ Primer", but I'm quite sure that they did it in "QT 4.6 - Gui Entwicklung" without iterators.
Well, you are over writting your pixmap that you drew in the first for loop.
Comment all the sections except the first one, and see if it gets written correctly.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
The pixmap won't get over written completly.
The pixmap that get's drawn in the second loop is just a little image that is nearly complete transparent (I'm working on a leveleditor for a 2D game and the image that gets drawn in the second loop is a little image that shows if the current tile is passable by the player or not.).
I commented anyway but that didn't change anything :-/
EDIT:
Whats interesting though, is that also the little "collsionimages" gets drawn incorrect.
I pretent that the error must be in the function where the original image gets tiled.
I'll add an image in a few minutes.
Last edited by LuckyBlade; 13th January 2011 at 13:15.
Ok, leave it commented out, so that we can easily find the problem.
In the screenshot you posted, there are 4 pixmaps - you get all 4 even with only one for loop in your paintEvent()?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Thats what I talked about in the last post.If you look at the "collisionimages" you'll see that they're also on the wrong position.
EDIT:
Yeah I get 4 images if I leave it commented.The result is the same.
I am sorry, how your answer is answering my question?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Sorry.
The result is the same as shown above in the image I posted.
This means that there is more code influencing your vector tiles, since more is drawn then is filled in the code you posted so far.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
LuckyBlade (13th January 2011)
Holy maccaroni!
I fixed it.
I changed
Qt Code:
for(int i = 0;i != goal;i++) { sourceVector->append(new Tile(rect,i,originalImage.copy(rect))); if(rect.x() + 32 >= originalImage.width()) { rect.setY(rect.y() + 32); rect.setX(0); }else rect.setX(rect.x() + 32); }To copy to clipboard, switch view to plain text mode
to
Everything works fine!Qt Code:
for(int i = 0;i != goal;i++) { sourceVector->append(new Tile(rect,i,originalImage.copy(rect))); if(rect.x() + 32 >= originalImage.width()) { rect.moveTop(32 + rect.y()); rect.moveLeft(0); }else rect.moveLeft(32 + rect.x()); }To copy to clipboard, switch view to plain text mode
If you had used my code from post 4 you'd had that solved since I was using setTopLeft().
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Bookmarks