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?
Getting data from an actor
Moderator: Coders of Rage
- ismetteren
- Chaos Rift Junior
- Posts: 276
- Joined: Mon Jul 21, 2008 4:13 pm
Re: Getting data from an actor
Doesn't the baseclass contain the common functions for retrieving those values?
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Getting data from an actor
You could cast them.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- ismetteren
- Chaos Rift Junior
- Posts: 276
- Joined: Mon Jul 21, 2008 4:13 pm
Re: Getting data from an actor
No, the base class does not have a getHealth, getScore, getPosition, get(everything that i ever might make an acotr that contained).Scoody wrote:Doesn't the baseclass contain the common functions for retrieving those values?
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
This should do the trick:
childptr = dynamic_cast<child*>(baseptr)
childptr = dynamic_cast<child*>(baseptr)
- ismetteren
- Chaos Rift Junior
- Posts: 276
- Joined: Mon Jul 21, 2008 4:13 pm
Re: Getting data from an actor
Really?Scoody wrote:This should do the trick:
childptr = dynamic_cast<child*>(baseptr)
Im gonna try that.
Thanks :D
.:Edit:.
i have read a little about it, and that dynamic_cast thing is really neat :D