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

Author Topic: Scrolling backgrounds / wrapping sprites at screen edge  (Read 13680 times)

0 Members and 2 Guests are viewing this topic.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Scrolling backgrounds / wrapping sprites at screen edge
« Reply #15 on: April 25, 2010, 04:38:42 pm »
Quote from: "Nexus"
Why create a temporary sprite?

Because of this:
Code: [Select]
void WrappingSprite::Render(sf::RenderTarget &target) const{
     (...)
     temp.Move(...);
}

Render is const, he can't move the sprite on this method, unless he creates a copy of it, which isn't actually nice to see, but..
Pluma - Plug-in Management Framework

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Scrolling backgrounds / wrapping sprites at screen edge
« Reply #16 on: April 25, 2010, 04:46:46 pm »
Quote from: "Sauce"
Unfortunately the problem still exists. It just refuses to wrap more than twice.
What about while (see my last post)?

Quote from: "gsaurus"
Render is const, he can't move the sprite on this method, unless he creates a copy of it, which isn't actually nice to see, but..
Oh, I didn't see that. But workarounds like temporary copies of the object itsself are a further hint that inheritance is misused. Using aggregation, this wouldn't be necessary.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Scrolling backgrounds / wrapping sprites at screen edge
« Reply #17 on: April 25, 2010, 05:08:13 pm »
Quote from: "Nexus"
Quote from: "Sauce"
Unfortunately the problem still exists. It just refuses to wrap more than twice.
What about while (see my last post)?


It's not the best option. The sprite should accompany the view every time it comes completely out of the screen.
Code: [Select]
if (sprite.GetPosition.x > viewRight)
       sprite.Move(-viewWidth, 0);
else if (sprite.GetPosition.x + sprite.GetSize().x < viewLeft)
       sprite.Move(viewWidth, 0);


You can't do this on the reder, this should be done somewhere else (like when you update the scroll).
Pluma - Plug-in Management Framework

Sauce

  • Newbie
  • *
  • Posts: 8
    • View Profile
Scrolling backgrounds / wrapping sprites at screen edge
« Reply #18 on: April 26, 2010, 03:39:30 pm »
It has to be done at render time because it relies on the current position of the View. Doing it at any other point in time would be pointless.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Scrolling backgrounds / wrapping sprites at screen edge
« Reply #19 on: April 26, 2010, 06:01:49 pm »
Quote from: "Sauce"
It has to be done at render time because it relies on the current position of the View. Doing it at any other point in time would be pointless.

All the render methods does is to draw stuff, not to update sprites, even if that update takes in account visual elements like pixels or the view. If you want a background sprite to accompany the view position by wrapping it every time it becomes out of the view, that must be done before its render method is called.

In other words, you should have a class handling the background and update it accordingly to current view position before drawing it.
Pluma - Plug-in Management Framework