Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Camera Following Sprite  (Read 2606 times)

0 Members and 1 Guest are viewing this topic.

Deadboy257

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Camera Following Sprite
« 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.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Camera Following Sprite
« Reply #1 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! :)
« Last Edit: September 26, 2015, 09:20:49 pm by mkalex777 »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Camera Following Sprite
« Reply #2 on: September 27, 2015, 03:37:18 pm »
If the official View tutorial (or API documentation) is not helpful to you, then maybe the explanation posted on the wiki 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.
« Last Edit: September 27, 2015, 03:39:48 pm by Jesper Juhl »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Camera Following Sprite
« Reply #3 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Camera Following Sprite
« Reply #4 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Camera Following Sprite
« Reply #5 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
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*