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

Author Topic: Views and sprite world positions  (Read 3985 times)

0 Members and 3 Guests are viewing this topic.

BitMaNip

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Views and sprite world positions
« on: October 11, 2024, 11:15:19 am »
Hi All,

Thanks for any help in advance.

I am getting really confused about views. I am using a view which is full screen (1:1). I am using a view as I have a tilemap based upon a vertex array and I can then move the view left and right to give me a scrolling tiledmap.

I understand the view is positioned by its centre.

Lets say my screen resolution is 1280pixels wide. So the view starts at the far left of my map with its centre at 640.f.

As I increase this position, it scrolls over my map.

But If I place a sprite beyond the screen size to the right, say perhaps world position of 1500.f (xpos), when my view passes this no sprite is drawn?

What am I doing wrong?


G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Views and sprite world positions
« Reply #1 on: October 11, 2024, 02:53:56 pm »
Don't forget to draw your sprite. (maybe :p )
Make sure you draw your tilemap before the sprite, otherwise the tilemap will be drawn on top of the sprite and you won't see it.
If you call setView, draw your sprite between setView and display.

BitMaNip

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Views and sprite world positions
« Reply #2 on: October 11, 2024, 04:44:13 pm »
Valid point. I am definitely drawing them as when I change their x position to within the viewport, they draw as expected.

I understand that, in other game dev that I did,  not using views, I would have to position the sprites relative to the offset from the world origin so they would render on screen.

i.e Sprite.x = Sprite.x - xDistanceFromOrigin

If this sprite was then within screen dims, it was rendered/drawn.

But i thought that if I move the view(camera) away from the origin, the sprites would sit where they are until ‘seen’ by the view? i.e a sprite with an xpos of 1300.f would just be outside of the view (width 1280 as per my rendertarget). As the view position moves to the right, without adjusting the sprite, it would eventually come into ‘view’.


But this is not happening?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Views and sprite world positions
« Reply #3 on: October 19, 2024, 05:41:20 pm »
Absolutely. It "just sits there" and then the view moves over it and it becomes visible. That's the idea behind the process indeed.

Anything you draw after "setting" the view will be drawn with that view. However, if the view is changed (set to a different view) or even if the current view is modified and then updated (which is the same as setting it to a modified version of that view), everything needs to be drawn under the new view.

With that said, the question really is: do you use more than one view and are you setting it to a different one before drawing the sprite?

It's also worth noting that if you have any calculations based on positions (and the like) of objects where you use things like "getPosition()", you should remember that it takes into account the view that is currently set "at the time of making those calculations."
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything