PDA

View Full Version : OOP question



Maqrkk
April 2nd, 2008, 08:34 AM
Hello,

I'm not really new to Flash, but I just need some advice or opinions.

I got a document class Control, and a Ball class.
I want to move the ball with the keyboard. In which class should I check for keyboardinput? Should I check in the Control and then move the ball from Control, or pass parameters and move the ball in Ball. Should I check in Ball?

Hope someone can help me decide.

ultraky
April 2nd, 2008, 09:11 AM
Your ball class

Your ball class should have everything that relates to what the ball does. Your Control class should just (for the most part) create and destroy the ball.

Maqrkk
April 2nd, 2008, 09:14 AM
So you're saying controls go in the Ball class. And I guess the collision detection goes in Control then? Thanks

Charleh
April 2nd, 2008, 09:17 AM
I'd create another class which handles input and have ball derive from this class - with the input class sending messages to the parent class using an interface or a set of common methods - that way you define the 'control schema' once and then build a class on top which reacts to the button presses - it just enables easy button mapping and 'special' keypresses and stuff like that

Maqrkk
April 2nd, 2008, 09:33 AM
That sounds complicated, and I do not really know how I would do that. Can you give me a hint for doing that?

Charleh
April 3rd, 2008, 04:19 AM
Well if it's simple movement just stick the code in Ball - if you need to control several different objects simultaneously or at different times using the same controls/same keys you could just do what I suggested - depends on what your requirements are

Maqrkk
April 3rd, 2008, 09:14 AM
It's simple controls, right/left, jump. So I guess I'll just stick them in Ball ;) Thanks.