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

Author Topic: Creating player class.  (Read 3238 times)

0 Members and 1 Guest are viewing this topic.

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Creating player class.
« 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)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Creating player class.
« Reply #1 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
}
 
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: Creating player class.
« Reply #2 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!

 

anything