SFML community forums

Help => Graphics => Topic started by: Kyubey on October 21, 2013, 04:37:59 pm

Title: Creating player class.
Post by: Kyubey on October 21, 2013, 04:37:59 pm
Hello there. I'm currently trying to implement player class to my game (here's the link to my topic with code if you're curious: http://en.sfml-dev.org/forums/index.php?topic=13253.0). However, I'm kind of stuck at how should I do it. Should I just redraw character sprite with each loop, with position depending on input? Is there some kind of method my brain cannot fathom? I'd appriciate any form of help on the matter.

(also, if there's a topic on this subject, then I'm sorry I made another one - search function gave me nothing)
Title: Re: Creating player class.
Post by: zsbzsb on October 21, 2013, 04:51:49 pm
Quote from: Kyubey
Should I just redraw character sprite with each loop, with position depending on input? Is there some kind of method my brain cannot fathom?

You always need to redraw everything each loop. Essentially you want a your main loop to look something like this.

int main()
{
      HandleInput(); // Do event processing
      Update(); // Update all npcs/players/entities based on input
      Draw(); // Draw everything to the screen
}
 
Title: Re: Creating player class.
Post by: Kyubey on October 21, 2013, 05:06:09 pm
God, now I feel stupid.. Yeah, you're totally right - I need to redraw everything with each loop so why not do character movement this way. I really should rethink stuff before posting - thanks for help!