Sign in to follow this  

Tile layers, vector problem [SOLVED]

This topic is 4302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I add an int to my vector how can I keep track of its posistion so I can remove it at a later stage. my code effectively does... remove(player.x, player.y) //pop an index off the vector move_player(); set(player.index, player.x, player.y) // push an index onto vector The problem with this is that if an object goes over another object, then the object underneath decides to move, it will erase the one at the top instead of its own index. When an object is created it sets itself to the tilemap. On a move event the object will erase its current posisition, move, then set it's new posistion. When an object erases its posistion, it simple pops an int off the tile space. This isn't what I need though. I need the correct tile index to be erased. i.e. the objects tile index might of been overlapped by another objects index. and it might be the same index so I can't use the index for ID. [Edited by - simon10k on March 5, 2006 4:53:29 AM]

Share this post


Link to post
Share on other sites
I'm not sure I understand exactly what you are trying to do here. Maybe posting the source code that uses the vector would help. My first thought though is that maybe a vector is the wrong container to use for your task. It sounds like you want to remove elements from the middle of the container which is much easier to do with a list. If you need to access elements by id, you may want to use an associative container such as a map.

Share this post


Link to post
Share on other sites
Yes, this is the way that i do it.Divide the big tile into smalls tiles.

But i wanted to know if it's possible with tiles of different dimensions.
its curiosity

:)

Share this post


Link to post
Share on other sites
lol, you posted in the wrong thread. Anyway I should be using a list -yes. Not sure about maps -haven't used them before. But to the best of my knowledge, wouldn't using a map rearrange the order of the tiles? The terrain tiles dont need id's.

I was using vectors for a reason, but the requirements have change. Before I was making all game objects unwalkable so I didn't have this problem.

Say a player walks ontop of a NPC, then the NPC moves. poping a tile of the vector/list isn't going to work. That would erase the players image instead of the player. My thoughts are that I will need to give all objects unique id's so my set and remove functions will take an id like

Set(int id, int x, int y);
Remove(int id, int x, int y);

I'll be removing elements from the middle, so yes a list would be better. I'll show some code later, tommorrow maybe. Ill have to iterate through the list and look for the id to remove the tile. I've like half sorted it out. It sounds a bit confusing, I know ;)

-Edit
I just realized that iterators dont become invalid when using a list.

[Edited by - simon10k on March 6, 2006 10:48:46 AM]

Share this post


Link to post
Share on other sites

This topic is 4302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this