sfml-tmxloader icon indicating copy to clipboard operation
sfml-tmxloader copied to clipboard

[Question] Insert players in map and change its texture

Open ghost opened this issue 9 years ago • 3 comments

Hi,

I am a student and this year we have to create a small video game in C ++. We decided to use some libraries to facilitate our work because we are beginner in C ++.

So, your librairy is very interesting but we didn't find the documentation and we have some basic questions (sorry if they are stupid :) ).

  1. How to insert the player in map between two layers to have a z-depth effect ? I tried to use a ImageLayer and modify its tile but it didn't work.
  2. When the player is inserted in the map, how to change its texture ?

Thank you and sorry for my bad english.

ghost avatar Nov 24 '15 00:11 ghost

Hi, you can render individual map layers if you need to, allowing you to render normal sprites in between, for example:

ml.Draw(rt, 0); //draw background
rt.draw(playerSprite);
ml.Draw(rt, 1); //draw front layer

there is also a blog post I wrote about layer ordering here. HTH

fallahn avatar Nov 24 '15 10:11 fallahn

Oh, thank you for your very fast answer,

So, I did that :

tmx::MapLoader ml("maps");
ml.Load("test.tmx");

sf::RenderTexture rt;
rt.create(ml.GetMapSize().x,ml.GetMapSize().y);

ml.Draw(rt, 0); 
rt.draw(playerSprite);
ml.Draw(rt, 1);

sf::Texture txt = rt.getTexture();
sf::Sprite sprite(txt);

...
window.draw(txt);
...

And of course, it works :)

I read your article and it's very interesting.

I think, we will create a sprite for player and add its collision points in the tmxmap for collision with objects on the map as you say in your article and in the programme a collision box for projectiles. Is it a good idea ?

Thank you again :)

ghost avatar Nov 24 '15 14:11 ghost

Hi, sounds like you're on the right track. I also wrote a couple of posts on collision testing which might be useful: http://trederia.blogspot.com/2013/10/collision-detection-with-tiled-maps.html and http://trederia.blogspot.com/2013/06/optimising-collision-testing.html

fallahn avatar Nov 24 '15 15:11 fallahn