Author Topic: How to arrange keyboard input code?  (Read 1018 times)

karlgoran

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
How to arrange keyboard input code?
« on: Thu, Dec 15, 2011 »
Hi. In my current program i look for which keys are pressed down in both my playstate and in the update function of my player class. Is this a good thing or is there some better way of arranging this?

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: How to arrange keyboard input code?
« Reply #1 on: Thu, Dec 15, 2011 »
Do both checks do the same thing? Or does the PlayState check for say "mute and unmute" and the player class check for movement?

If they do the same thing I'd refactor it and remove that - keep keyboard input in one central place, for your sanity as well as flixels. It doesn't matter if you do it in your PlayState and that tells your Player class "move left" etc, or do it in your Player class. If you only ever have 1 PlayState for the whole game there's no real benefit either way. If you're going to have more than one state (maybe multiple levels) then do it in the Player class.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius