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

Author Topic: Proper way of moving an image atlas.  (Read 1545 times)

0 Members and 1 Guest are viewing this topic.

dysoco

  • Newbie
  • *
  • Posts: 3
    • View Profile
Proper way of moving an image atlas.
« on: March 11, 2014, 12:31:18 am »
Hello.

I recently implemented image atlas into my "game", basically I have the following:

class TextureAtlas {
    sf::Texture texture;
    std::map<std::string, std::shared_ptr<sf::Sprite>> sprites;
    std::shared_ptr<sf::Sprite> current;
}
 

where each shared_ptr<sf::Sprite> points to the sprite representing a region of the Texture (using IntRect). current points to the current Sprite to be drawn (you change it when reading keyboard input).

Everything is fine to this point, but now I've come across a big problem: how do I move my player?

So far I've been moving it with "player.sprite.move(x, y)", however, now I realized that when I move a sprite, the other sprites don't move: thus it's extremely confusing and they just jump around.

So my question is... what do you do? is there a way to tell the RenderTarget to draw a sprite in a certain position? (So I can keep my own sf::Vector2f position and implement my own move method). Or is moving all sprites at once the only way (which sounds inefficient)?

Any example code or tips?

Thanks.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Proper way of moving an image atlas.
« Reply #1 on: March 11, 2014, 12:56:45 am »
...
what do you do? is there a way to tell the RenderTarget to draw a sprite in a certain position?
Yes. setPosition() before you draw.

(So I can keep my own sf::Vector2f position and implement my own move method). Or is moving all sprites at once the only way (which sounds inefficient)?

Any example code or tips?
If you want to moce a sprite, move it. If you want to move 100 sprites, then move each of them. Then draw.

Mutoh

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Proper way of moving an image atlas.
« Reply #2 on: March 11, 2014, 12:57:40 am »
I think that what you need is sf::View. Here's how you use them: http://www.sfml-dev.org/tutorials/2.0/graphics-view.php

It will enable you to move the "world" without having to move any singular entity. If you want your player to move, or any other entity, just move it, and don't care about anyone else's movement - everything regarding the "whole image" should be taken care by the View.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Proper way of moving an image atlas.
« Reply #3 on: March 11, 2014, 01:02:52 am »
I think that what you need is sf::View. Here's how you use them: http://www.sfml-dev.org/tutorials/2.0/graphics-view.php

It will enable you to move the "world" without having to move any singular entity. If you want your player to move, or any other entity, just move it, and don't care about anyone else's movement - everything regarding the "whole image" should be taken care by the View.
Yeah, that's probably what he's looking for - good point! I didn't see that; focused to much on what was said about moving individual sprites.

 

anything