Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Insert players in map and change its texture #47

Open
ghost opened this issue Nov 24, 2015 · 3 comments
Open

[Question] Insert players in map and change its texture #47

ghost opened this issue Nov 24, 2015 · 3 comments
Labels

Comments

@ghost
Copy link

ghost commented Nov 24, 2015

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 ghost changed the title Insert players in map and change its texture [Question] Insert players in map and change its texture Nov 24, 2015
@fallahn
Copy link
Owner

fallahn commented Nov 24, 2015

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

@ghost
Copy link
Author

ghost commented Nov 24, 2015

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 :)

@fallahn
Copy link
Owner

fallahn commented Nov 24, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant