We play with our kids. We roll around on the floor and play with blocks and draw pictures. At the same time we nurture, feed, clothe, and educate them. So while we are playing and goofing off and having fun, in that split second that they do something that goes against what you have taught them, like throwing something across the room, slapping, or any other thing that children shouldn't do, how do you flip the switch between playmate to parent to educate them that what they did was wrong but then be able to transition back to playmate?
Well, first of all i don't think its we that need to flip a switch, play-time is just as important in parenting as feeding your child, its food for their soul.
But to answer the question:
You don't. Its upon how your child reacts to your response.
NOTE: "Merel" is the name of our 4 year old daughter.
In our home when playtime goes bad we first give her a warning:"Merel, i don't want to see that! [name the situation you don't want to see]". Make sure you make eye-contact. Usually she said:"Ok, sorry." and we can continue as we were.
If that fails, we add a consequence:"Merel, i don't want to see that again! or else we cant play with [insert whatever we were doing]!". Make sure you make eye-contact again. But usually when she is acting out like that for a second time its because she is bored, or looking for borders(to cross).
if a third time happens, we execute the consequence. IF it happens, cause after the 2nd warning, we usually try to hand her alternatives of what we are doing or get her to focus on what we were doing again. Although this does not remove conflict entirely, cause sometimes they are just looking to see how far they can go, which is good.
Some extra tips:
Its important to be consistent, sit down with your wife/girlfriend and make a rule for yourself on how you are going to discipline your child, and do not break this rule, ever. Its very important that we make things predictable for them, and in not doing so you will just end up adding fuel to the fire.
Never just take/copy advise from peers, just because it works for our family does not mean it could work for you, every kid is unique. Adapt where needed, keeping consistency in mind.
Make eye contact when explaining, and get on the same level, physically. Presenting yourself as large as possible only adds to his/her feeling of unfairness and can even intimidate them.
One interesting approach is the one championed by Teacher Tom (teachertomsblog.blogspot.com). Basically, make informative statements about your child's actions and their effects on the world ("You're hurting me." or "You said thank you to the lady at the store, and, see, it made her smile.", "I can't let you do this, it's dangerous") and model the behavior you'd like to see.
For our family, in terms of play, it means stopping tickling when our daughter asks us to (in our house, "no" always means "no"). It means being respectful in our interventions with her (saying please and thank you when we ask her to help with something), explaining unpleasant but essential physical procedures beforehand (like administrating medicine by force, or holding her for a vaccine, if she's not willing to do it on her own), giving her options whenever possible.
That attitude does not change whether we're playing or "parenting" - we're always attempting to treat her the way we'd like to be treated if we turned into not fully capable and slightly demented adults (something that might happen someday after all).