Drawing map on the screen


#1

Hello! Im trying to draw a map from a file and it’s not working as I want it to work.
Here are the classes:

Tile.h and .cpp
https://pastebin.com/YttcnACE

Layer.h
https://pastebin.com/aMrsmhtr
Layer.cpp
https://pastebin.com/s1imKLQC

Map.h
https://pastebin.com/hd0Vbv2L

Map.cpp
https://pastebin.com/RYsgCcnb

FileManager.cpp
https://pastebin.com/PFk9jMdG

Map.cfg
https://pastebin.com/w5JxiF9M

Load=[Attributes] - it’s like we want to load text or image, we pass there text then after that contents are like what text we want to display or what image we want to show. In this case there is an image 96x32 and every 32 frame got a different color which draw our map, [2,0] means it’s blue, [1,0] means it red, the first coordinate contains x, the second y.

Code is based on Coding Made Easy allegro 5 platformer tutorial…


#2

Please write copyright notice to the beginning of each and every file of your code, so that other people don’t have to suffer again from DMCA requests. The copyright notice either has to be open source, or at least giving people right to use your files at the time when they are helping you. The easiest is to write that you wrote it, and that the code is public domain. Thank you.


#3

Also, please upload your complete code to pastebin or similar since it’s very hard to read your first post, because of the incorrect indentation, incorrect ‘Summary’ usage and so on.


#5

No. No copyright notices. i think as a minimum it should be this added to the beginning of every file:
/*
Written in < YEAR > by < AUTHOR NAME >
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide.
*/
See the longer version there https://wiki.creativecommons.org/wiki/CC0_FAQ .
This license doesn’t prevent you to change your code later and put it under a different license. If you want to use another license, it’s more complicated, and it’s on you.
With no copyright notices it’s copyrighted by you or by anyone who may claim it, and you put all people who change your code to help you, in risk of their material taken down from anywhere immediately by DMCA notices by anyone, no matter whether true or false. So not adding the copyright notices to all files, is deliberately causing trouble to the people who help you. Weird clown show as it all is, but this is how it is by law.


#6

Is now all good there?


#7

No, not good at all, no copyright notices.


#8

No? Is it must to have? I dont know what do you mean. I wrote what you wanted me to wrote. It’s not necessary. I don’t need copyright notices. I need help with this.


#9

Then you deliberately put in risk people who help you, it is a question whether anyone is willing to help you then.


#10

Ok. I think there will be guy who will be able to help me without this. Let’s stop spamming post.


#11

There may be, then one does it by ones own risk. All are warned.


#12

Just read through your code.
In what way does it not work? You’ll need to be more specific than “not working as I want it to work”.


#13

Load=[Attributes] - it’s like we want to load text or image, we pass there text then after that contents are like what text we want to display or what image we want to show. In this case there is an image 96x32 and every 32 frame got a different color which draw our map, [2,0] means it’s blue, [1,0] means it red, the first coordinate contains x, the second y.

That means the code is loading a map from file based on x and y coordinates which are described as a SolidTiles.
It doesn’t display on the screen, I mean, the map discribed as StartLayer doesn’t display.

Tile handles functions of loading and render image
Layer loads from file, cuts the image and gives SolidTiles a good frame(if I can say it like that).
Map loads everyrthing on the screen.


#14

Set out breakpoints in the code.
Check that the map, it’s layer(s) and so on is properly created.
Check that the config file and it’s data is properly loaded.
You should also check, whenever the code executes Map::Draw(SDL_Renderer *renderer), that there’s actually something to render (i.e, check that the tiles list inside the layer class is not empty etc).
There’s a few lists/vectors used in your code so check that all of those are correctly filled with data.


#15

Seems like Map class renders from file correctly. I mean, it’s written that layers[0] takes texture from Files/Images/tileSheet.png and that’s a good way. Cutting image going well in Layer.cpp, but it doesn’t know the texture what is obvious, because we declare the texture in Map.cpp. Config file is loaded properly because everything is written in a console. In Gameplay class render seems well as well. It takes good layer id (return size = 1) and map id = “Map”, so it’s as it should be render.


#16

Hm, okay. It’s hard for me to debug the code only by reading through the code via pastebin. Do you mind uploading your whole project, with all the code, textures(s), config file(s) and so on, to dropbox or similar webspace? By doing this I could easily debug and breakpoint your project and (might) find out what’s wrong with it.

There’s a copyright claim earlier in this thread but since I don’t planning on taking/using your code whatsoever, you don’t really need to go through that trouble. But if you do feel that you want to, just add the copyright information at the top of each source file.


#17

Yes here it goes, the person i helped who wrote DMCA notice about me and took down my project, also put ones files in dropbox i guess, though i think there were other places too. And this was all about these files that person referred to in dropbox, etc, that one claimed to be ones copyright, after one received all help needed. So i don’t understand why such hostility of not adding copyright notices to files, it were intelligent and polite at least, when refusing to accept any other importance.

I never took or used any of that code referred by that person, only used it to help that person. I had to upload the built project somewhere, so that person can get it. But it is that wherever you upload it, while they are there, anyone can write DMCA notice about these files, and no matter whether right or wrong that notice is, all your other content there will be immediately taken down. This is what happened, this is the law. I removed all the links to that file anywhere, but couldn’t delete it, as some files cannot be deleted in github, and maybe also in other places. But this was not enough for that person who i helped, one still submitted the DMCA notice and took down the single project i had in github,

So i don’t understand why such hostility, and why many people here think it’s ok.


#18

I don’t know why it’s so important to you. I did it, I dont know it’s good or not, though. There you go:


#19

“To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem”, heheh, but that’s good enough, perfect :slight_smile:


#20

I’ve managed to locate the problem in your code now.

The reason why your map isn’t rendered is because the texture that’s supposed to be loaded in each tile (a tileset texture I assume) isn’t loaded correctly. The texture in each tile is therefore not valid and no tile is being rendered.

The reason why the texture isn’t loaded correctly is because the filepath being passed into each tile is incorrect.

In your Layer class, in the LoadContent function, you’re looping through your attributes vector.
In the if (att == "TileSheet") statement, the tileSheet texture is being correctly loaded (so far so good) but later in the loop, the filepath that’s being passed into each tile is incorrect.
So the problem that you need to fix is in the if(contents[i][k] != "---") statement, where you’ve written this: tiles[tiles.size() - 1].SetContent(con, tempState, posX, posY, renderer);.
The con string variable consists of --- and no filepath to an image file.


#21

Yeah, I was thinking about it. I’ll try my best and call later, thank you by now.
Edit: What if I’ll pass contents[i][k] there? When I set breakpoint, it says contents[i][k] = “2,0”, so seems like it’s going well, but still nothing shows…
Edit : Oh! I think I got it. I created std::string conn and set it in if(att == “TileSheet”) as conn = con and then tiles[tiles.size() - 1].SetContent(conn, tempState, posX, posY, renderer); . But everything is red. Why tTile.first is all the time 0?
Edit: I moved SDL_Rect from tile.draw to tile.SetContent and in layer.loadContent set tiles[tiles.size() - 1].SetContent(conn, tempState, posX, posY, renderer, imageRect); like this and now it works.
Thank you very much for any help.