SFML community forums

Help => Graphics => Topic started by: Deadboy257 on September 26, 2015, 08:38:07 pm

Title: Camera Following Sprite
Post by: Deadboy257 on September 26, 2015, 08:38:07 pm
I've Been Working On A Game But I Cant Figure Out How To Get The View To Follow A Sprite. I Looked At The SFML Tutorial For View And It Didn't Seem To Help Me Figure Out It At All.
Title: Re: Camera Following Sprite
Post by: mkalex777 on September 26, 2015, 09:11:30 pm
Just assign your sprite coordinates to View.Center property.
For zoom-in/zoom-out you can multiply window size with camera scale factor and assign result to View.Size. That all what you need.
I'm using it and it works very well :)

Manual for view looks a little bit confusing, but actually it's very simple.
View.Center is used to shift your view around coordinate system.
View.Size is used to stretch specified size in your coordinate system to full view size on the real screen.
View.Viewport is used to setup positio and size of view on the real screen, it uses coordinates from 0 to 1, which is equivalent to the screen left/top to right/bottom.

Very clear, simple and fast! :)
Title: Re: Camera Following Sprite
Post by: Jesper Juhl on September 27, 2015, 03:37:18 pm
If the official View tutorial (http://www.sfml-dev.org/tutorials/2.3/graphics-view.php) (or API documentation (http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1View.php)) is not helpful to you, then maybe the explanation posted on the wiki (https://github.com/SFML/SFML/wiki/Tutorial%3A-Using-View) may be.
By the way, what's going on with your capitalization of every word in your question? Please stop that, it's annoying to read.
Title: Re: Camera Following Sprite
Post by: Hapax on September 28, 2015, 07:27:19 pm
By the way, what's going on with your capitalization of every word in your question? Please stop that, it's annoying to read.
Spaced Camel Case?  ;D
I totally agree with you. It's almost as bad as all capitals.
Title: Re: Camera Following Sprite
Post by: shadowmouse on September 28, 2015, 08:07:05 pm
Spaced Camel Case?  ;D
I totally agree with you. It's almost as bad as all capitals.
[pedanticness] Isn't it Spaced Pascal Case? With PascalCase being camelCase with the first letter capitalised (especially as this is a programming website and the SFML contribution guidelines makes the distinction). [/pedanticness] I also agree that it's annoying.
Title: Re: Camera Following Sprite
Post by: Hapax on September 28, 2015, 10:08:46 pm
[pedanticness] Isn't it Spaced Pascal Case?...[/pedanticness]
Bah. That's what I meant to write  :P