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

Author Topic: How can i get in sfml the previous position of a sprite?  (Read 1230 times)

0 Members and 2 Guests are viewing this topic.

meistertigran

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
How can i get in sfml the previous position of a sprite?
« on: December 28, 2012, 12:35:36 pm »
I'm trying to write a Classical Snake game, and i need to get the previous position of the head from my snake to create the first part of the snake body, and then the next part with the previous position of the first body part and so on.
Any Ideas ?
Sorry for my bad English.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How can i get in sfml the previous position of a sprite?
« Reply #1 on: December 28, 2012, 12:45:50 pm »
Wrong forum, correct would be Help->General.

Why don't you just simply store the previous position? If you don't know how to do that, you should learn some more C++ before you approach game programming...

Anyway, I would model the snake as a sequence (STL container) of segments. Each time step, you remove the tail segment, and insert a new head segment at the front. You don't need to relocate segments.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

meistertigran

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: How can i get in sfml the previous position of a sprite?
« Reply #2 on: December 28, 2012, 12:54:13 pm »
Good idea. Thanks.