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

Author Topic: Need help with tile map  (Read 1340 times)

0 Members and 1 Guest are viewing this topic.

jdm1891

  • Newbie
  • *
  • Posts: 17
    • View Profile
Need help with tile map
« on: April 26, 2016, 10:42:34 pm »
Hello everyone! I made a tile map with the tutorial a while back, I've been trying to make a "CreateVariation()" function, that goes downwards for different versions of the same tile, and randomly picks one.

This doesn't seem to be working, it seems to be printing on the screen the whole thing downwards and not just the one tile.

http://imgur.com/Xl8AHF0 this is the result when compiled

https://github.com/jdm1891/games this is the source code - I believe the problem is the texture rect made

The tilemap function that creates the tile map is line 46 of tileMap.cpp - I believe the problem is there

any help would be lovely thank you!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10988
    • View Profile
    • development blog
    • Email
Re: Need help with tile map
« Reply #1 on: April 27, 2016, 12:52:25 pm »
I don't understand what the problem is. What should the function do? And what is it doing instead?
Have you run the application in a debugger or printed out some debug values to see what is going on?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jdm1891

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Need help with tile map
« Reply #2 on: April 27, 2016, 03:03:31 pm »
http://imgur.com/3oXA8l5 - here is my tileset.png - as you can see it has tiles going right, and variation of each tile going downward.

My plan was for each tile(e.g. GRASS) it pick a random one of the variations and use that.

instead for each tile it gets, it prints the tile, and then everything below that tile(including transparency)

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Need help with tile map
« Reply #3 on: April 27, 2016, 06:16:53 pm »
It may be helpful if you could strip down your code to a minimal example. Right now it is hard to grasp what all of the variables are for without spending a decent amount of time looking through all the files.

I did take a quick look, though, and my initial impression is that the math in TileMap::create() doesn't seem right.
int tu = tileNumber % ( _texture.getSize().x / _textureSize.x );
int tv = tileNumber / ( _texture.getSize().x / _textureSize.x );
 

First of all, I'm assuming texture.getSize().x is the width of the entire tilemap texture and _textureSize.x is the width of a single tile. If you are wanting to randomly pick tiles in the manner you talked about in your first post, what is tv supposed to be for? It seems like tileNumber should only contain a value between 0-2 inclusive (because your tilemap has 3 tiles horizontally on the first line). Do you allow your level to specify tiles other than ones on the first line? If so, that may complicate things. If not, then I don't see how tv will ever equal anything other than 0.

quad[0].texCoords = sf::Vector2f(tu * _textureSize.x, tv * (_textureSize.y + createVariation(i, j)));
quad[1].texCoords = sf::Vector2f((tu + 1) * _textureSize.x, tv * (_textureSize.y + createVariation(i, j)));
quad[2].texCoords = sf::Vector2f((tu + 1) * _textureSize.x, (tv + 1) * (_textureSize.y + createVariation(i, j)));
quad[3].texCoords = sf::Vector2f(tu * _textureSize.x, (tv + 1) * (_textureSize.y + createVariation(i, j)));
 

Why are you calling createVariation() for each corner of the quad. Shouldn't you just call it once and use that value for all 4 corners. I'm also, again, not sure what tv is for. Shouldn't that y value just be something like

variation * _textureSize.y
or
(variation + 1) * _textureSize.y

 

anything