I know about views, I just don't know how to get it to follow a sprite in a top-down view.
You need to have a pointer to the sprite and use the sprites GetCenter() functions and the views SetCenter(). Something like this:[cpp]
sf::Sprite* follow = &some_sprite
view.SetCenter(follow->GetCenter());[/cpp]
im dumb
[cpp]sf::Sprite* follow = &Player;[/cpp]
try that
Yeah, my mistake didn't put in the &. Still it doesn't work. I put "view.SetCenter(follow->GetCenter());" in the game loop and when I compile and run the background is flickering and stuff, the camera doesn't move.
And I don't understand HalfSize, the window is 800x600, what should I put in the HalfSize of the view?
[QUOTE=DarkSpirit05er;17142350]Yeah, my mistake didn't put in the &. Still it doesn't work. I put "view.SetCenter(follow->GetCenter());" in the game loop and when I compile and run the background is flickering and stuff, the camera doesn't move.
And I don't understand HalfSize, the window is 800x600, what should I put in the HalfSize of the view?[/QUOTE]
Uh, you put half the size of the view. For 800x600 you would create the view like this:
[cpp]sf::View view(sf::Vector2f(400.f, 300.f), sf::Vector2f(400.f, 300.f));[/cpp](you can obviously change the center to whatever you need)
Updated OP with non-working script.
[editline]09:44PM[/editline]
And to whomever is rating me funny deserves a punch in the face. I'm learning to program, I don't have full knowledge of everything so I'm terribly sorry if I make mistakes (not).
Set the view before drawing.
Did, this happened:
[img]http://img32.imageshack.us/img32/6497/38941320.png[/img]
But the weird flickering stopped.
GetCenter might return a local vector (dunno tbh).
Try View.SetCenter(follow->GetPosition()).
Worked, thanks a lot! Although it seems like I need a really big background. Thanks again.
Sorry, you need to Log In to post a reply to this thread.