Page 1 of 1

Getting data from an actor

Posted: Sun Mar 08, 2009 1:20 pm
by ismetteren
The way i have my actor/gameobject system in my game working, is that the actors themself only stores some data (position, health, sprite and so on). They does not update themself nor does they draw themself. I have gamelogic and rendere classes to do that.

So i can pretty easily acces a actor from the actor vector. The problem is, that i am using polymorphisem(i am pretty sure that is spelled wrong) to store different kind of actors in the same vector. That means, if i want to access a value specific to a certain kind of actor, i can't do it!

I am pretty sure im not the only one who is structuring my program in this way. So, how do you solve this problem?

Re: Getting data from an actor

Posted: Sun Mar 08, 2009 4:13 pm
by Scoody
Doesn't the baseclass contain the common functions for retrieving those values?

Re: Getting data from an actor

Posted: Sun Mar 08, 2009 11:30 pm
by MarauderIIC
You could cast them.

Re: Getting data from an actor

Posted: Mon Mar 09, 2009 8:15 am
by ismetteren
Scoody wrote:Doesn't the baseclass contain the common functions for retrieving those values?
No, the base class does not have a getHealth, getScore, getPosition, get(everything that i ever might make an acotr that contained).

Cast. Can i cast from a baseclass to a child class, if i can, How? just a normal cast?

Re: Getting data from an actor

Posted: Mon Mar 09, 2009 9:17 am
by Scoody
This should do the trick:
childptr = dynamic_cast<child*>(baseptr)

Re: Getting data from an actor

Posted: Mon Mar 09, 2009 2:10 pm
by ismetteren
Scoody wrote:This should do the trick:
childptr = dynamic_cast<child*>(baseptr)
Really?

Im gonna try that.

Thanks :D

.:Edit:.
i have read a little about it, and that dynamic_cast thing is really neat :D