Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TileMap renders different if array is in header and not in source  (Read 5783 times)

0 Members and 1 Guest are viewing this topic.

albert_lazaro

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Good afternoon,

I have found an strange behaviour (sure it's a stupid question) but I was doing a tileMap for my game following the SFML example https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php#example-tile-map and the result is:



(This is the good image - the tilemap is smaller than the screen, so it displays the black space)

The int array is created in the buildScene function of class world and passed to the tilemap in the same function.

The problem is that if I create the array in the header file it shows more sprites than normal.



Also, I had changed the c style array to a std::vector that is created in the header and filled in the constructor and it gives the same problem.

Do you know what is happening?

PD printing the array in World::buildScene and TileMap::load gives the same array.

buildScene
1 1 1 1 1 1 1 1 1 1 1 1 1 33 33 291 1 1 1 1 1 1 1 1 1 65 101 99 1 1 32 1 289 1 1 1 1 65 67 1 1 1 1 1 1 1 1 1 0 65 67 1 1 32 32 32 32 1 1 1 1 65 67 1 1 32 1 1 10 11 1 1 1 97 99 1 1 32 32 1 42 43 1 1 1 1 1 1 1 230 231 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 
TileMap::load
1 1 1 1 1 1 1 1 1 1 1 1 1 33 33 291 1 1 1 1 1 1 1 1 1 65 101 99 1 1 32 1 289 1 1 1 1 65 67 1 1 1 1 1 1 1 1 1 0 65 67 1 1 32 32 32 32 1 1 1 1 65 67 1 1 32 1 1 10 11 1 1 1 97 99 1 1 32 32 1 42 43 1 1 1 1 1 1 1 230 231 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


------------------------

header file: https://github.com/lazaro92/fantasy-maker/blob/feature/1/Include/Book/World.hpp
src file: https://github.com/lazaro92/fantasy-maker/blob/feature/1/Source/World.cpp
« Last Edit: April 29, 2021, 09:10:15 pm by albert_lazaro »

LucasM

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: TileMap renders different if array is in header and not in source
« Reply #1 on: April 30, 2021, 04:52:40 am »
I have absolutely no idea.  Just make sure your bounds are set properly?  Looks like accessing data that has not been set. Either out of bounds, or you are creating a vector slightly larger than your map data and the last elements are not being initialized in any logical (to you) order.
ie. in the example if doing a vector resize, resizing bigger than needed by 2 rows.  So the renderer tries to draw two rows of unknown values.
Are you passing the right height value to load?  If you are using the same code as the example that could be it.

Edit.  Just noticed that you attached code samples, so ignore the last line.  Still have no idea.  Could be something to do with the rendering code or map loading code.
« Last Edit: April 30, 2021, 05:00:16 am by LucasM »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: TileMap renders different if array is in header and not in source
« Reply #2 on: April 30, 2021, 08:03:08 am »
The code on github is the version that works, right? It would be more relevant to show us the code that doesn't work ;)
Laurent Gomila - SFML developer

albert_lazaro

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: TileMap renders different if array is in header and not in source
« Reply #3 on: April 30, 2021, 07:19:54 pm »
I have updated the code and I will check what mLucas is saying...

albert_lazaro

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: TileMap renders different if array is in header and not in source
« Reply #4 on: April 30, 2021, 07:26:55 pm »
I knew it would be a stupid question. The problem is that I'm passing width for the width param and also for the height param, so ii's adding extra data to the vertex array. I didn't see it.

mTileMap.load(texture, TILE_SIZE, mLevel, tileMapWidth, tileMapWidth);
                                                                                 this is height param ----^

This thread can be deleted. Or it can help other people. I don't know.
« Last Edit: April 30, 2021, 07:29:13 pm by albert_lazaro »