Animators and EventReceivers

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
freezzo
Posts: 27
Joined: Thu Mar 08, 2007 6:36 pm
Contact:

Animators and EventReceivers

Post by freezzo »

I am trying to create a camera using an animator, as I here that is the "accepted" way now. I have it working fine, except the camera's control logic is buried within the OnEvent. I assume this is fine. My question comes when I need to add more OnEvents for other nodes, like my player, how do I handle that? Do I temporarily turn off the cameras event receiver while processing other input? Or should I create a master event receiver and pass events to this camera/player/etc?

Thanks
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animators and EventReceivers

Post by CuteAlien »

Events get passed on unless the eventreceiver returns true (which means event is done). So depends on your receivers if you need to disable the other one or if they can run in parallel. Or maybe your animator can take a scenenode pointer and can control both the camera and the player and you would want to move the animator around instead.

There are just different solutions and it's hard to give general hints. You don't even have to use animators - I often just use update functions instead if it fits the rest of the program architecture better.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Animators and EventReceivers

Post by REDDemon »

You can switch event receivers by "setEventReceiver". Or you can use a event receiver that act like a filter wich decides to wich sub-event receiver sends an event.

For example

Code: Select all

 
onEvent(SEvent & event)
{
    if(character1->isActive())
        return character1->onEvent(event);
 
    if(character2->isActive())
        return character2->onEvent(event);
    
    return false;
}
 
or

Code: Select all

 
onEvent(SEvent & event)
{
    if(character1)
        if(charater1->onEvent(event)
            return true;
    
    if(character2)
        if(charater2->onEvent(event)
            return true;
    
    return false;
}
 
of course you can register a sub event receiver in your own event receiver.

Code: Select all

 
onEvent(SEvent & event)
{
    if(registeredReceiver !=0)
        return registeredReceiver->OnEvent(event);
 
    return false;
}
 
irrlicht is very flexibile with events. You can use the approach you prefer. At a certain level you need also how irrlicht internally handle things (you must know how certain events are generated and how to stop other events) but this is in general not limiting.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply