Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Wenzil

Member Since 01 Aug 2012
Offline Last Active Yesterday, 11:02 PM
-----

#5050459 OOP Newb: Am I doing this right?

Posted by Wenzil on 05 April 2013 - 06:49 PM

This is just a general OOP guideline, but it fits this particular example very well. According to Law of Demeter (see http://en.wikipedia.org/wiki/Law_of_Demeter), the clients of your Player class (in this case, Game) should not know about the Sprite subcomponent. So in your Player class you would have a Move(float x, float y) method defined like this:

 

void Player::Move(float x, float y) {
    sprite.move(x, y)
}

 

Then, inside Game.cpp, instead of moving the player's sprite directly, you just tell the player to move, and the player will take care of moving its sprite.

 

Similarly, you should define the Player constructor to set the sprite's origin and initial position, instead of having Game.cpp do it.

 

 




PARTNERS